Fix zero-sized allocation crash on Windows#3085
Merged
copybara-service[bot] merged 2 commits intogoogle-deepmind:mainfrom Feb 16, 2026
Merged
Fix zero-sized allocation crash on Windows#3085copybara-service[bot] merged 2 commits intogoogle-deepmind:mainfrom
copybara-service[bot] merged 2 commits intogoogle-deepmind:mainfrom
Conversation
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 google-deepmind#2992
mmossg
approved these changes
Feb 11, 2026
JayFoxRox
reviewed
Feb 13, 2026
src/engine/engine_util_errmem.c
Outdated
| // pad size to multiple of 64 | ||
| if ((size%64)) { | ||
| size += 64 - (size%64); | ||
| if (size == 0) { |
There was a problem hiding this comment.
This feels a bit like fighting symptoms? Why do zero size allocations exist in the first place?
Maybe add a warning (or similar) here?
Another strategy might be to simply return NULL here to avoid the error + avoid allocation overhead.
There's also a corresponding check in mju_free which returns if a !ptr.
Contributor
Author
|
Hi @JayFoxRox, thanks for the feedback. Zero-size allocations occur when models contain empty arrays (e.g., no flex or mesh elements). Returning NULL for size 0 is indeed cleaner since mju_free already handles NULL pointers. I have updated the implementation to return NULL for zero-sized requests instead of padding to 64 bytes. |
mmossg
approved these changes
Feb 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request fixes a crash on Windows when models contain empty arrays.
Changes
Fixes #2992