Skip to content

Commit 60f9b34

Browse files
quaglacopybara-github
authored andcommitted
Validate the MjModel pointer passed to MjData constructor.
Fixes #2426. PiperOrigin-RevId: 785411895 Change-Id: If698120b5a4ab4ac457d35760380c140b1b5a208
1 parent 8b94bd0 commit 60f9b34

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

python/mujoco/structs.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,12 @@ This is useful for example when the MJB is not available as a file on disk.)"));
728728

729729
// ==================== MJDATA ===============================================
730730
py::class_<MjDataWrapper> mjData(m, "MjData");
731-
mjData.def(py::init<MjModelWrapper*>());
731+
mjData.def(py::init([](MjModelWrapper* m) {
732+
if (!m) {
733+
throw py::type_error("MjModel cannot be None");
734+
}
735+
return MjDataWrapper(m);
736+
}));
732737
mjData.def_property_readonly("_address", [](const MjDataWrapper& d) {
733738
return reinterpret_cast<std::uintptr_t>(d.get());
734739
});

0 commit comments

Comments
 (0)