Skip to content

Conversation

@Ashutosh0x
Copy link

PR Description: Improve USD Plugin Detection and Memory Robustness

This Pull Request introduces enhancements to MuJoCo's USD integration and improves memory allocation diagnostics, with a focus on cross-platform reliability (Windows/MinGW/macOS).

Changes

1. Robust USD Plugin Resource Discovery (#3004)

  • Search Path Expansion: Updated src/experimental/usd/utils.cc to search for mujoco-usd-resources in both the current library directory and the sibling lib directory. This is essential for Windows where DLLs often sit in a bin folder while resources reside in lib.
  • Linker Path Resolution: Fixed the plugInfo.json generation in src/experimental/usd/CMakeLists.txt to correctly point to the bin directory for shared libraries on Windows. This ensures that USD can actually load the plugins it registers.

2. Enhanced Memory Error Diagnostics (#2992)

  • Detailed Error Messages: Modified src/engine/engine_util_errmem.c to include the requested allocation size in the "Could not allocate memory" fatal error. This provides immediate clarity on whether a crash is due to system exhaustion or an invalid (e.g., massive) size request from program logic.
  • Windows Safety Check: Ensured that mju_malloc handles 0-sized requests gracefully. On Windows, _aligned_malloc(0) returns NULL, which was previously triggered a fatal "out of memory" error. We now ensure a minimum valid allocation to prevent these false-positive crashes.

Verification

  • Manually reviewed search path logic for POSIX and Windows compatibility.
  • Verified that the plugInfo.json paths resolve correctly for standard Windows installation structures.
  • Ensured that the addition of the <vector> header in utils.cc does not conflict with existing builds.

These improvements make it much easier for Windows users to use the new USD features and provide better tools for debugging memory-related issues.

- Fix redefined 'stat' error in MinGW (src/user/user_resource.cc)
- Fix MinGW stack flag syntax in MujocoLinkOptions.cmake
- Remove stack flags from Python modules to prevent Windows load crashes
- Enable thread-safe localtime_s for MinGW (src/engine/engine_util_errmem.c)
- Handle 0-sized mju_malloc on Windows to prevent crashes
- Fix USD resource discovery on Windows by searching both 'bin' and 'lib' directories
- Correct plugInfo.json library paths for Windows installations
- Include requested allocation size in 'Could not allocate memory' error messages
- Add safety check for 0-sized memory requests on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant