Commit Graph

22 Commits

Author SHA1 Message Date
Yuval Tassa 4a9364082e Fix data race lazy-init spin lock deadlock on Windows.
PiperOrigin-RevId: 942556300
Change-Id: Iffe7a3e71c0f6273603e2ada14bf8d924b0ee6cf
2026-07-04 12:07:34 -07:00
Georg Ostrovski bb80b55ae1 Fix data race in mju_getLogConfigPtr lazy init
The lazy init of log_config used a single atomic flag (env_checked) with
a load-then-store pattern, allowing two threads to both enter the init
path and concurrently write to the non-atomic log_config.topics field.

Replace with a two-phase atomic init: an atomic exchange on
env_init_claimed ensures exactly one thread enters the init, while
env_init_done (with acquire/release semantics) signals completion and
provides the happens-before edge that makes log_config writes visible to
other threads.

Also adds mj_atomic_exchange_bool to engine_crossplatform.h (both MSVC
and GCC/Clang variants).

PiperOrigin-RevId: 941202181
Change-Id: I59b6801c7b4b8b0e1647d82d2aeb534a90fb66fb
2026-07-01 11:24:36 -07:00
Yuval Tassa a070535c65 Fix GCC -Wformat-truncation error in legacy log adapter
Widen snprintf buffer from 1024 to 2048 bytes in mju_defaultLogHandler
to avoid truncation warning when formatting "func: subject".

PiperOrigin-RevId: 930823501
Change-Id: I0b2246f23c44e983bea76976b684d2efdfdff29c
2026-06-11 17:23:43 -07:00
Yuval Tassa 58f6d52491 Introduce new logging API, fixes #858
PiperOrigin-RevId: 930744288
Change-Id: I6ec1203b55c031390f3eef23192e2337508ce886
2026-06-11 14:36:57 -07:00
Yuval Tassa 062b0f1ea6 Remove deprecated mju_{error,warning}_{i,s} functions.
PiperOrigin-RevId: 925204136
Change-Id: Ia877d08a135092db8037d04e6a237e81325a1d7c
2026-06-02 01:59:05 -07:00
Copybara-Service 3a99f6110e Merge pull request #3084 from Ashutosh0x:fix/mingw-stat-localtime
PiperOrigin-RevId: 880906196
Change-Id: I98027e80e9882620cb184766c14110478178ce53
2026-03-09 09:54:10 -07:00
ashutosh0x 04e5df08a9 Update mju_malloc to return NULL for zero-sized allocations 2026-02-13 19:22:05 +05:30
ashutosh0x c962188655 Fix zero-sized allocation crash on Windows
On Windows, _aligned_malloc(0) returns NULL, which MuJoCo interprets as a fatal out-of-memory error. This causes crashes on models with empty arrays.

Ensure a minimum allocation of 64 bytes for any 0-sized request.

Fixes #2992
2026-02-11 22:33:28 +05:30
ashutosh0x 2ab76ec4f5 Fix MinGW stat redefinition and thread-safe localtime
- Guard #define stat _stat with !defined(__MINGW32__) to avoid conflicts with MinGW's own POSIX-compliant stat implementation

- Replace _MSC_VER check with defined(_WIN32) for localtime_s to allow all Windows compilers including MinGW to use the secure function

Fixes #3038, #3037
2026-02-11 22:32:21 +05:30
Yuval Tassa edbdb5195c Change MuJoCo engine source code function-spacing convention from 3 blank lines to 2
PiperOrigin-RevId: 813754244
Change-Id: I6836e41c3b021cb727e922c25c60f629b9814c93
2025-10-01 07:58:17 -07:00
Google DeepMind eb6f7dc6b7 Gate some calls with __EMSCRIPTEN__
PiperOrigin-RevId: 762520516
Change-Id: If9f7729721bab8c947861a968cf96eecc6591228
2025-05-23 12:10:52 -07:00
Yuval Tassa 2545ec5383 Don't call getchar on error.
PiperOrigin-RevId: 752680097
Change-Id: Idce87a3e33ebce703bf3eedc18026f6a13d05f35
2025-04-29 04:37:22 -07:00
Saran Tunyasuvunakool 329ed193ac Disallow variable-length arrays and turn on -Wpedantic in Clang and GCC.
PiperOrigin-RevId: 562832747
Change-Id: I0532624cee31e089a47426305d885687eb0fc5c5
2023-09-05 11:05:04 -07:00
Kyle Bayes 93012bf164 Remove legacy MacOS support in mju_alignedMalloc. As of MuJoCo 2.3.7, MacOS 11 is the oldest supported version of MacOS.
PiperOrigin-RevId: 555090388
Change-Id: I57d7abf17952da250f1165f24dfcbb112aea92f9
2023-08-09 01:58:10 -07:00
Kyle Bayes ac1f41160d Add engine internal error macro mjERROR to prepend calling function to error function.
PiperOrigin-RevId: 541584847
Change-Id: I57447e64375413ee07aa96372a402e1ced59ff4a
2023-06-19 03:29:31 -07:00
Yuval Tassa 455b1cd2e2 Add spaces around comparison operators in engine source files.
PiperOrigin-RevId: 535989348
Change-Id: I883f7e82351299933c49b35a31842b5d8d6aea04
2023-05-28 05:02:34 -07:00
Saran Tunyasuvunakool f887c1e928 Add ASAN and MSAN instrumentation for arena and mjData stack.
PiperOrigin-RevId: 535635490
Change-Id: Ia1e58771bae25bf72c861f57452fb8faa2b918fb
2023-05-26 09:17:26 -07:00
Kyle Bayes d3d789cf7d Convert mju_error and mju_warning to variadic functions, supporting printf-like arguments. The functions mju_error_i, mju_error_s, mju_warning_i, and mju_warning_s are now deprecated.
PiperOrigin-RevId: 515431052
Change-Id: I440de0cb417ce216b6d636a5d86dc9ef6cc1fc06
2023-03-09 13:51:27 -08:00
Alessio Quaglino fd4d47e4a5 Format memory warning in human-friendly way.
PiperOrigin-RevId: 486610408
Change-Id: I6beecb12059e69f4407e921d20efc54ce6b3f491
2022-11-07 02:56:07 -08:00
Saran Tunyasuvunakool b849023069 Miscellaneous linting in src/engine.
PiperOrigin-RevId: 462415459
Change-Id: I6c79c592613c6b0a665af06faf945586bb6ba32d
2022-07-21 10:16:49 -07:00
Saran Tunyasuvunakool 5cc73c30bf Align all arrays in mjData's buffer to 64 byte boundaries.
The introduction of additional mjData arrays for the implicit integrator caused in a shift in data alignment in memory. In certain combinations of machines and models, this change resulted in ~5% performance regression that appears to be attributable to L2 cache misses.

This change aligns all arrays in mjData to the boundary of a typical L2 cache line size. Benchmarking shows that this resolves the performance regression on a Broadwell machine.

PiperOrigin-RevId: 451652783
Change-Id: I4ed2c2d03453a83a0b4a9b8e224e2fd7c0dadea9
2022-05-28 13:03:38 -07:00
Saran Tunyasuvunakool 1913a02b40 Initial open sourcing of MuJoCo.
PiperOrigin-RevId: 450374687
Change-Id: Ie3225a46ce095fc28ae8e63c326a640261f562bb
2022-05-23 01:08:49 -07:00