Skip to content

Fix #3139: support UTF-8 file paths on Windows via mju_fopen#3375

Open
Ashutosh0x wants to merge 1 commit into
google-deepmind:mainfrom
Ashutosh0x:fix/issue-3139
Open

Fix #3139: support UTF-8 file paths on Windows via mju_fopen#3375
Ashutosh0x wants to merge 1 commit into
google-deepmind:mainfrom
Ashutosh0x:fix/issue-3139

Conversation

@Ashutosh0x

Copy link
Copy Markdown
Contributor

Problem

On Windows, MuJoCo uses fopen throughout its C/C++ layer. fopen on Windows uses the system ANSI code page, which means file paths containing UTF-8 characters (non-ASCII) fail to open even though the paths are valid.

Fixes #3139.

Changes

src/engine/engine_util_file.h (new file)

Introduces mju_fopen, a thin wrapper around fopen:

  • On Windows: converts the UTF-8 filename and mode strings to wide (wchar_t) using MultiByteToWideChar(CP_UTF8, ...) and calls _wfopen. Falls back to fopen on allocation failure.
  • On all other platforms: directly calls fopen with zero overhead.

The function is static inline in a header so it requires no new compile unit and has no ABI impact.

Callers updated to use mju_fopen instead of fopen:

  • src/engine/engine_io.cmj_saveModel
  • src/engine/engine_print.cmj_printFormattedModel, mj_printFormattedData, mj_printFormattedScene
  • src/engine/engine_util_errmem.c — log-to-file handler, mju_writeLog
  • src/user/user_api.ccmj_encode
  • src/user/user_util.ccFileToMemory
  • src/xml/xml_api.ccmj_saveLastXML

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)

1 participant