Introduce a new header `gil.h` defining `MutexLockIfGilDisabled` to support thread-safety in both standard and free-threaded CPython builds.
Protect critical shared states and registries:
- Guard global Python callback pointers in `callbacks.cc` using a mutex. Move `gil_scoped_acquire` into local blocks around refcount modifications to prevent `longjmp` from bypassing destructors.
- Protect raw pointer maps in `structs_wrappers.cc` with static mutexes.
- Replace TOCTOU race in `mjcb_time` initialization with thread-safe `std::call_once`.
- Add synchronization to lazy indexer array cache initialization in `indexers.cc` and `indexer_xmacro.h`.
- Protect vector mutations in `StructListBase::PopulateUpTo` in `structs.h` with a mutex.
- Revert unnecessary atomic changes to threadpool counters.
- Declare free-threading compatibility by passing `pybind11::mod_gil_not_used()` to all extension modules.
Fixes#3259Fixes#3256Fixes#2978
PiperOrigin-RevId: 941101502
Change-Id: Iec4ce58afcbc75d4b0be6a9a21fc8a47854242e3
This change introduces MjVFS, an explicit object to mirror the C mjVFS. This is meant to replace the MjSpec.assets dict. This latter while convenient guides users towards harmful authoring patterns with respect to data duplication and spec attachment workflows. Making VFS management explicit should encourage better memory usage and allow us to make better compile time optimizations.
From this change, `spec.assets` is deprecated. However we will temporarily support backwards compatibility due to the wide spread usage. An error will be thrown if calling code tries to use a spec that uses both the assets dict and the new MjVfs.
PiperOrigin-RevId: 908772050
Change-Id: I77c6d0369307fc300c954768fed17401261e18da
mjrRect is a common type that will be re-used across different
rendering APIs, not just mjr_ APIs.
PiperOrigin-RevId: 882620060
Change-Id: I7f77ac9298c52c454d94c46379ff5270fd833f26
The pybind for recompile was not releasing the GIL when it called mj_recompile, this can caused deadlocks with the
asset loading threads. For example if a resource provider was trying to call Python.
To resolve this the GIL is release just for the mj_recompile.
Addresses: https://github.com/google-deepmind/mujoco/issues/3118
* Replace various MJOPTION_ macros with a single MJOPTION_FIELDS.
* Use XVEC macro to denote vector members where there is a mixture of
vector and scalar members in a given struct type.
* Split up MJVISUAL_FIELDS into separate macros for each substruct.
* Modify engine_print.c and Python bindings struct.h/cc to use the
new X macros.
PiperOrigin-RevId: 869760513
Change-Id: Idac4fe9aa99f0258e7c79802ca9023a0d4486e2d
This change updates all size-related members within the `mjModel` struct from `int` to `mjtSize`. This allows MuJoCo to handle models with a larger number of elements. Corresponding changes were made to macros, function signatures, and I/O routines to accommodate the new `mjtSize` type.
PiperOrigin-RevId: 860144595
Change-Id: I701c6d607715d240766b6210a9773cd9e4258c59
This allows other modules to depend on functions such as FromRawPointer that previously were only defined in the _struct python module.
PiperOrigin-RevId: 745619670
Change-Id: I9f1af60cb665c00d853b7ca38201b37302d278af
This method allows users to bind a spec to a model or data object, making it less verbose to access its arrays.
PiperOrigin-RevId: 699952211
Change-Id: I6b71a88d5a6968bc0f902bd49db7c568b46a4dfb
When loading models in the XML bindings, different issues with the asset dictionary were all reported as "assets dict is too big".
PiperOrigin-RevId: 670960339
Change-Id: I2e47d91a6b433fd90ebdf9960a9b5b47413af410
This CL adds error handling to the mj_recompile function. If the recompile fails, the function will return -1 and set the error message in the spec. The Python wrapper for mj_recompile will catch the error and raise a ValueError exception.
PiperOrigin-RevId: 666784579
Change-Id: I225eca1769ea839c782be3c03fc4ff1ea5885a48
Also add metadata fields to the Python bindings of mjModel and mjOption,
and fix dtype of a number of fields.
PiperOrigin-RevId: 654138876
Change-Id: If2bbe41bf3dfdb350d60b5289afc65fffb397ce9
In MjDataWrapper.__deepcopy__ use the Python implementation of MjModelWrapper.__deepcopy__ to make an object that Python knows about and can release later.
Fixesgoogle-deepmind/mujoco#1572.
PiperOrigin-RevId: 644967999
Change-Id: I95d093c672e136122e1939f69463a4d29dad82e8
Orthographic cameras are specified by setting the `orthographic` attribute of the `<camera>` element. The `fovy` attribute is still used to specify the field-of-view, but its semantic is different for orthographic cameras. For orthographic cameras, the field-of-view is expressed in units of length, rather than degrees.
Other related changes:
* Fix bug in the ordering of `cam_xxx` elements in `mjModel`.
* Make camera visualization translucent only when the frustum is visualized.
* Added a button to `simulate` to toggle between perspective and orthographic free cameras.
https://youtu.be/ZXBTEIDWHhs
PiperOrigin-RevId: 642293435
Change-Id: Id090a421ad88ab404b5b27ddbbd6bfc81ad49bc5
Rename `light_radius` -> `light_bulbradius`, make the default value 0.02.
PiperOrigin-RevId: 627032170
Change-Id: I1e01e2eca028c0aefc2e7dc384e8b34abac184aa
Before this change, MjDataWrapper contained a custom data structure called MjDataMetadata, which contained the sizes of various arrays needed to create MjData. This was used for serialization and deserialization, as well as copying MjData instances.
This worked fine for native MuJoCo models, but as soon as plugins were used, there was information in the model that was needed and not available in MjDataMetadata. Since plugins are so general, keeping MjDataMetadata was untenable.
PiperOrigin-RevId: 578205355
Change-Id: I11b9ee797d1da5aaf1fecbbe170b3b0f1f1a3e6c