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
This commit is contained in:
ashutosh0x
2026-02-11 22:33:28 +05:30
parent cc5d544d15
commit c962188655
+4 -2
View File
@@ -207,8 +207,10 @@ void* mju_malloc(size_t size) {
// default allocator
else {
// pad size to multiple of 64
if ((size%64)) {
size += 64 - (size%64);
if (size == 0) {
size = 64;
} else if ((size % 64)) {
size += 64 - (size % 64);
}
// allocate