From 0c315563470f6519fe9e985c4fd85ae0050bbee2 Mon Sep 17 00:00:00 2001 From: Fedor Chelnokov Date: Wed, 9 Sep 2026 19:16:03 +0300 Subject: [PATCH] Stop glfwInit changing the working directory on macOS GLFW_COCOA_CHDIR_RESOURCES defaults to true, so glfwInit() chdirs into the .app bundle's Contents/Resources when that directory exists. It runs before anything reads the command line, so every relative path the app is given resolves from inside the bundle: a mesh file, a python script, a credentials file. Nothing here wants that - resources are located through SystemPath, not the working directory. Measured on a packaged MeshInspector.app: a file placed in Contents/Resources opens when passed as ./name.json, while the same file in the working directory does not, and ../../.. from the command line reaches the directory holding the .app. A bundle without Contents/Resources, such as a build tree one, is unaffected because the chdir silently fails, which is why this went unnoticed. --- source/MRViewer/MRViewer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/MRViewer/MRViewer.cpp b/source/MRViewer/MRViewer.cpp index fc95bdd606b6..893ddf4662b8 100644 --- a/source/MRViewer/MRViewer.cpp +++ b/source/MRViewer/MRViewer.cpp @@ -858,6 +858,12 @@ int Viewer::launchInit_( const LaunchParams& params ) #endif #endif +#if defined( __APPLE__ ) + // Otherwise glfwInit() chdirs into Contents/Resources of the .app bundle, + // and every relative path given on the command line resolves from there. + glfwInitHint( GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE ); +#endif + if ( !glfwInit() ) { spdlog::error( "glfwInit failed" );