Browse Source

cocoadisplay: Call remove_all_windows() when the application is about to close

Part of #1321
LD 3 years ago
parent
commit
5fa3f3eb68

+ 1 - 1
panda/src/cocoadisplay/cocoaGraphicsWindow.mm

@@ -99,7 +99,7 @@ CocoaGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
   if (NSApp == nil) {
     [CocoaPandaApp sharedApplication];
 
-    CocoaPandaAppDelegate *delegate = [[CocoaPandaAppDelegate alloc] init];
+    CocoaPandaAppDelegate *delegate = [[CocoaPandaAppDelegate alloc] initWithEngine:engine];
     [NSApp setDelegate:delegate];
 
 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060

+ 8 - 1
panda/src/cocoadisplay/cocoaPandaAppDelegate.h

@@ -14,9 +14,16 @@
 #import <Foundation/Foundation.h>
 #import <AppKit/AppKit.h>
 
+class GraphicsEngine;
+
 // Cocoa is picky about where and when certain methods are called in the initialization process.
-@interface CocoaPandaAppDelegate : NSObject<NSApplicationDelegate>
+@interface CocoaPandaAppDelegate : NSObject<NSApplicationDelegate> {
+  @private
+    GraphicsEngine *_engine;
+}
 
+- (id) initWithEngine:(GraphicsEngine *)engine;
 - (void)applicationDidFinishLaunching:(NSNotification *)notification;
+- (void)applicationWillTerminate:(NSNotification *)notification;
 
 @end

+ 16 - 0
panda/src/cocoadisplay/cocoaPandaAppDelegate.mm

@@ -12,12 +12,28 @@
 */
 
 #import "cocoaPandaAppDelegate.h"
+#include "graphicsEngine.h"
 
 @implementation CocoaPandaAppDelegate
 
+- (id) initWithEngine:(GraphicsEngine *)engine {
+
+  if (self = [super init]) {
+    _engine = engine;
+  }
+
+  return self;
+}
+
 - (void)applicationDidFinishLaunching:(NSNotification *)notification {
   // This only seems to work when called here.
   [NSApp activateIgnoringOtherApps:YES];
 }
 
+- (void)applicationWillTerminate:(NSNotification *)notification {
+  // The application is about to be closed, tell the graphics engine to close
+  // all the windows.
+  _engine->remove_all_windows();
+}
+
 @end