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
This commit is contained in:
Matija Kecman
2026-06-24 04:17:49 -07:00
committed by Copybara-Service
parent a3039224ba
commit 38956ed95c
+9 -3
View File
@@ -44,10 +44,16 @@ PYBIND11_MODULE(sim, m) {
.def(
"advance",
[](StepControl& self, py::object model_obj, py::object data_obj) {
auto& model = py::cast<mujoco::python::MjModelWrapper&>(model_obj);
auto& data = py::cast<mujoco::python::MjDataWrapper&>(data_obj);
mjModel* m = nullptr;
mjData* d = nullptr;
if (!model_obj.is_none()) {
m = py::cast<mujoco::python::MjModelWrapper&>(model_obj).get();
}
if (!data_obj.is_none()) {
d = py::cast<mujoco::python::MjDataWrapper&>(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.")