Fix UTF-8 file path handling on windows#3155
Open
mar-yan24 wants to merge 3 commits intogoogle-deepmind:mainfrom
Open
Fix UTF-8 file path handling on windows#3155mar-yan24 wants to merge 3 commits intogoogle-deepmind:mainfrom
mar-yan24 wants to merge 3 commits intogoogle-deepmind:mainfrom
Conversation
2 tasks
havess
approved these changes
Mar 6, 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.
Summary
Fixes #3139: MuJoCo fails to load XML files from directories containing non-ASCII characters (e.g., Japanese, Chinese) on Windows.
The cause of the issue was that on Windows,
fopen()and_stat()default to ANSI encoding, not UTF-8. Paths with non-ASCII characters get jumbled, producing errors like:ParseXML: Error opening file 'C\temp\UTF-8(randomchars)\cube\cube_3x3x3.xml'I fixed this using a cross-platform wrapper
mju_fopen()that converts UTF-8 paths to wide strings viaMultiByteToWideCharand calls_wfopenon Windows, passing through tofopenon other platforms. Similarly fixedstat→_wstatin the VFS layer.All file-opening call sites are updated:
engine_util_errmem.c/h—mju_fopen()implementation and declarationengine_io.c—mj_saveModelengine_print.c—mj_printFormattedModel/Data/Sceneuser_util.cc—FileToMemory(key XML loading path)user_vfs.cc—OpenFile(_stat→_wstatwrapper)xml_api.cc—mj_saveLastXML,mj_printSchema,mj_saveXMLxml_util.cc—mju_getXMLDependenciesTest plan
In line with best contribution practices, I also wrote a short testcase for
mju_fopeninengine_util_errmem_test.cc.These tests consist of
All 8 tests in
engine_util_errmem_testpassed.