diff --git a/python/mujoco/structs.cc b/python/mujoco/structs.cc index 4501d593..0c0e5958 100644 --- a/python/mujoco/structs.cc +++ b/python/mujoco/structs.cc @@ -728,7 +728,12 @@ This is useful for example when the MJB is not available as a file on disk.)")); // ==================== MJDATA =============================================== py::class_ mjData(m, "MjData"); - mjData.def(py::init()); + 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(d.get()); });