From d51db6e39e0c50aa2ce2f02321b32e5f22c36fdc Mon Sep 17 00:00:00 2001 From: Donny Lawrence Date: Sun, 13 Jan 2019 11:46:57 -0500 Subject: [PATCH 1/2] Fix an instance where a macOS window will stick around when trying to have it destroyed. This commit also removes an extraneous call to [_window setReleasedWhenClosed], which is already set in cocoaPandaWindow's init method. --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index c3f23d4013..0a140109c7 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -711,8 +711,11 @@ close_window() { } if (_window != nil) { - [_window setReleasedWhenClosed: YES]; [_window close]; + + // Process events once more so any pending NSEvents are cleared. Not doing + // this causes the window to stick around after calling [_window close]. + process_events(); _window = nil; } From 2c513ba1c43811b328544eec0c722fa76d3d91c8 Mon Sep 17 00:00:00 2001 From: Donny Lawrence Date: Sun, 13 Jan 2019 19:07:43 -0500 Subject: [PATCH 2/2] Move handle_close_event() call to windowShouldClose, which only triggers when the close button is pressed by the user. --- panda/src/cocoadisplay/cocoaPandaWindowDelegate.h | 1 - panda/src/cocoadisplay/cocoaPandaWindowDelegate.mm | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/panda/src/cocoadisplay/cocoaPandaWindowDelegate.h b/panda/src/cocoadisplay/cocoaPandaWindowDelegate.h index 1a80ef056e..93d5b7b35b 100644 --- a/panda/src/cocoadisplay/cocoaPandaWindowDelegate.h +++ b/panda/src/cocoadisplay/cocoaPandaWindowDelegate.h @@ -34,7 +34,6 @@ class CocoaGraphicsWindow; - (void)windowDidBecomeKey:(NSNotification *)notification; - (void)windowDidResignKey:(NSNotification *)notification; - (BOOL)windowShouldClose:(id)sender; -- (void)windowWillClose:(NSNotification *)notification; // TODO: handle fullscreen on Lion. diff --git a/panda/src/cocoadisplay/cocoaPandaWindowDelegate.mm b/panda/src/cocoadisplay/cocoaPandaWindowDelegate.mm index 6b93410538..7e39748bd1 100644 --- a/panda/src/cocoadisplay/cocoaPandaWindowDelegate.mm +++ b/panda/src/cocoadisplay/cocoaPandaWindowDelegate.mm @@ -50,11 +50,11 @@ } - (BOOL) windowShouldClose:(id)sender { - return _graphicsWindow->handle_close_request(); -} - -- (void) windowWillClose:(NSNotification *)notification { - _graphicsWindow->handle_close_event(); + bool should_close = _graphicsWindow->handle_close_request(); + if (should_close) { + _graphicsWindow->handle_close_event(); + } + return should_close; } @end