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:
@@ -207,8 +207,10 @@ void* mju_malloc(size_t size) {
|
|||||||
// default allocator
|
// default allocator
|
||||||
else {
|
else {
|
||||||
// pad size to multiple of 64
|
// pad size to multiple of 64
|
||||||
if ((size%64)) {
|
if (size == 0) {
|
||||||
size += 64 - (size%64);
|
size = 64;
|
||||||
|
} else if ((size % 64)) {
|
||||||
|
size += 64 - (size % 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate
|
// allocate
|
||||||
|
|||||||
Reference in New Issue
Block a user