Validate the MjModel pointer passed to MjData constructor.

Fixes #2426.

PiperOrigin-RevId: 785411895
Change-Id: If698120b5a4ab4ac457d35760380c140b1b5a208
This commit is contained in:
Alessio Quaglino
2025-07-21 06:22:50 -07:00
committed by Copybara-Service
parent 8b94bd0ef6
commit 60f9b34a77
+6 -1
View File
@@ -728,7 +728,12 @@ This is useful for example when the MJB is not available as a file on disk.)"));
// ==================== MJDATA ===============================================
py::class_<MjDataWrapper> mjData(m, "MjData");
mjData.def(py::init<MjModelWrapper*>());
mjData.def(py::init([](MjModelWrapper* m) {
if (!m) {
throw py::type_error("MjModel cannot be None");
}
return MjDataWrapper(m);
}));
mjData.def_property_readonly("_address", [](const MjDataWrapper& d) {
return reinterpret_cast<std::uintptr_t>(d.get());
});