diff --git a/darwin/main.m b/darwin/main.m index 1c2c7255..0532bf5e 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -70,7 +70,23 @@ void uiMain(void) void uiQuit(void) { - [uiprivApp stop:uiprivApp]; + @autoreleasepool { + NSEvent *e; + + [uiprivApp stop:uiprivApp]; + // stop: won't register until another event has passed; let's synthesize one + // TODO instead of using NSApplicationDefined, create a private event type for libui internal use only + e = [NSEvent otherEventWithType:NSApplicationDefined + location:NSZeroPoint + modifierFlags:0 + timestamp:[[NSProcessInfo processInfo] systemUptime] + windowNumber:0 + context:[NSGraphicsContext currentContext] + subtype:0 + data1:0 + data2:0]; + [uiprivApp postEvent:e atStart:NO]; // let pending events take priority (this is what PostQuitMessage() on Windows does so we have to do it here too for parity; thanks to mikeash in irc.freenode.net/#macdev for confirming that this parameter should indeed be NO) + } } // thanks to mikeash in irc.freenode.net/#macdev for suggesting the use of Grand Central Dispatch for this diff --git a/zOLD_darwin/main.m b/zOLD_darwin/main.m index 91c6d1a6..18e7ae59 100644 --- a/zOLD_darwin/main.m +++ b/zOLD_darwin/main.m @@ -59,19 +59,6 @@ static BOOL stepsIsRunning; if (!canQuit) uiprivImplBug("call to [NSApp terminate:] when not ready to terminate; definitely contact andlabs"); - [uiprivNSApp() stop:uiprivNSApp()]; - // stop: won't register until another event has passed; let's synthesize one - e = [NSEvent otherEventWithType:NSApplicationDefined - location:NSZeroPoint - modifierFlags:0 - timestamp:[[NSProcessInfo processInfo] systemUptime] - windowNumber:0 - context:[NSGraphicsContext currentContext] - subtype:0 - data1:0 - data2:0]; - [uiprivNSApp() postEvent:e atStart:NO]; // let pending events take priority (this is what PostQuitMessage() on Windows does so we have to do it here too for parity; thanks to mikeash in irc.freenode.net/#macdev for confirming that this parameter should indeed be NO) - // and in case uiMainSteps() was called stepsIsRunning = NO; }