Skip to content

Fix UTF-8 file path handling on windows#3155

Open
mar-yan24 wants to merge 3 commits intogoogle-deepmind:mainfrom
mar-yan24:mark-enhancements
Open

Fix UTF-8 file path handling on windows#3155
mar-yan24 wants to merge 3 commits intogoogle-deepmind:mainfrom
mar-yan24:mark-enhancements

Conversation

@mar-yan24
Copy link
Copy Markdown
Contributor

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 via MultiByteToWideChar and calls _wfopen on Windows, passing through to fopen on other platforms. Similarly fixed stat_wstat in the VFS layer.

All file-opening call sites are updated:

  • engine_util_errmem.c/hmju_fopen() implementation and declaration
  • engine_io.cmj_saveModel
  • engine_print.cmj_printFormattedModel/Data/Scene
  • user_util.ccFileToMemory (key XML loading path)
  • user_vfs.ccOpenFile (_stat_wstat wrapper)
  • xml_api.ccmj_saveLastXML, mj_printSchema, mj_saveXML
  • xml_util.ccmju_getXMLDependencies

Test plan

In line with best contribution practices, I also wrote a short testcase for mju_fopen in engine_util_errmem_test.cc.

These tests consist of

  • ASCII path round-trip (write + read)
  • Nonexistent file returns NULL
  • UTF-8 path round-trip with Japanese characters (gracefully skips if the filesystem doesn't support UTF-8)

All 8 tests in engine_util_errmem_test passed.

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.

MuJoCo files in a directory containing UTF-8 fail to load (Windows only)

2 participants