diff --git a/readme.html b/readme.html
index 19e4285d..36c5add2 100644
--- a/readme.html
+++ b/readme.html
@@ -313,6 +313,7 @@ version of GLFW.
[Cocoa] Replaced NSDate
time source with mach_absolute_time
[Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
[Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
+ [Cocoa] Bugfix: glfwInit
changed the current directory for unbundled executables
[X11] Added support for the GLX_EXT_swap_control
extension as an alternative to GLX_SGI_swap_control
[X11] Added the POSIX CLOCK_MONOTONIC
time source as the preferred method
[X11] Added dependency on libm, where present
diff --git a/src/cocoa_init.m b/src/cocoa_init.m
index 2c747515..c8d5aed7 100644
--- a/src/cocoa_init.m
+++ b/src/cocoa_init.m
@@ -72,6 +72,18 @@ NSString* GLFWNameKeys[] =
};
+//========================================================================
+// Change to our application bundle's resources directory, if present
+//========================================================================
+static void changeToResourcesDirectory(void)
+{
+ char* resourcePath = [[[NSBundle mainBundle] resourcePath] UTF8String];
+
+ if (access(resourcePath, R_OK) == 0)
+ chdir(resourcePath);
+}
+
+
//========================================================================
// Try to figure out what the calling application is called
//========================================================================
@@ -87,24 +99,18 @@ static NSString* findAppName(void)
[name isKindOfClass:[NSString class]] &&
![@"" isEqualToString:name])
{
+ _glfwLibrary.NS.bundled = GL_TRUE;
return name;
}
}
// If we get here, we're unbundled
- if (!_glfwLibrary.NS.unbundled)
- {
- // Could do this only if we discover we're unbundled, but it should
- // do no harm...
- ProcessSerialNumber psn = { 0, kCurrentProcess };
- TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+ ProcessSerialNumber psn = { 0, kCurrentProcess };
+ TransformProcessType(&psn, kProcessTransformToForegroundApplication);
- // Having the app in front of the terminal window is also generally
- // handy. There is an NSApplication API to do this, but...
- SetFrontProcess(&psn);
-
- _glfwLibrary.NS.unbundled = GL_TRUE;
- }
+ // Having the app in front of the terminal window is also generally
+ // handy. There is an NSApplication API to do this, but...
+ SetFrontProcess(&psn);
char** progname = _NSGetProgname();
if (progname && *progname)
@@ -210,16 +216,16 @@ int _glfwPlatformInit(void)
return GL_FALSE;
}
- NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
-
- if (access([resourcePath cStringUsingEncoding:NSUTF8StringEncoding], R_OK) == 0)
- chdir([resourcePath cStringUsingEncoding:NSUTF8StringEncoding]);
-
- // Setting up menu bar must go exactly here else weirdness ensues
+ // Setting up the menu bar must go between sharedApplication
+ // above and finishLaunching below, in order to properly emulate the
+ // behavior of NSApplicationMain
setUpMenuBar();
[NSApp finishLaunching];
+ if (_glfwLibrary.NS.bundled)
+ changeToResourcesDirectory();
+
_glfwPlatformSetTime(0.0);
_glfwLibrary.NS.desktopMode =
diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h
index 93492dbb..582b338d 100644
--- a/src/cocoa_platform.h
+++ b/src/cocoa_platform.h
@@ -91,7 +91,7 @@ typedef struct _GLFWlibraryNS
// dlopen handle for dynamically loading OpenGL extension entry points
void* OpenGLFramework;
- GLboolean unbundled;
+ GLboolean bundled;
id desktopMode;
id delegate;
id autoreleasePool;