From 38956ed95c32eb7ff8920b443a4e2bfa8eff64f9 Mon Sep 17 00:00:00 2001 From: Matija Kecman Date: Wed, 24 Jun 2026 04:17:49 -0700 Subject: [PATCH] Handle None values for model and data in StepControl.advance. The `StepControl.advance` method now checks if the provided `model` or `data` Python objects are `None` before attempting to cast them to `MjModelWrapper` or `MjDataWrapper`, passing `nullptr` to the underlying C++ function if they are `None`. This fixes an oversight in the python bindings, C++ code already supported null models. PiperOrigin-RevId: 937243996 Change-Id: Ie67b8603517e7390fb54bfefbfed79ccf7b2bc5e --- python/mujoco/experimental/studio/sim.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/mujoco/experimental/studio/sim.cc b/python/mujoco/experimental/studio/sim.cc index 1a6906b5..dbc4b363 100644 --- a/python/mujoco/experimental/studio/sim.cc +++ b/python/mujoco/experimental/studio/sim.cc @@ -44,10 +44,16 @@ PYBIND11_MODULE(sim, m) { .def( "advance", [](StepControl& self, py::object model_obj, py::object data_obj) { - auto& model = py::cast(model_obj); - auto& data = py::cast(data_obj); + mjModel* m = nullptr; + mjData* d = nullptr; + if (!model_obj.is_none()) { + m = py::cast(model_obj).get(); + } + if (!data_obj.is_none()) { + d = py::cast(data_obj).get(); + } py::gil_scoped_release no_gil; - return self.Advance(model.get(), data.get()); + return self.Advance(m, d); }, py::arg("model"), py::arg("data"), "Step physics forward, respecting speed settings and refresh budget.")