Skip to content

Commit

Permalink
Trigger demo quit from applicationWillTerminate
Browse files Browse the repository at this point in the history
Allows for a clean shutdown of the rendering thread (CVDisplayLink) whilst the main thread is exiting
  • Loading branch information
Zorro666 authored and jeremyk-lunarg committed May 31, 2021
1 parent daa3490 commit 6149e30
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
11 changes: 10 additions & 1 deletion cube/macOS/cube/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#import "AppDelegate.h"
#import "DemoViewController.h"

@interface AppDelegate ()

Expand All @@ -29,7 +30,15 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
NSApplication *app = aNotification.object;
NSArray<NSWindow *> *windows = app.windows;
for (NSUInteger i = 0; i < windows.count; ++i) {
NSViewController *viewController = windows[i].contentViewController;
if ([viewController isKindOfClass:[DemoViewController class]]) {
[(DemoViewController *)viewController quit];
break;
}
}
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
Expand Down
3 changes: 3 additions & 0 deletions cube/macOS/cube/DemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

/** The main view controller for the demo storyboard. */
@interface DemoViewController : NSViewController

- (void)quit;

@end

#pragma mark -
Expand Down
8 changes: 6 additions & 2 deletions cube/macOS/cube/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ @implementation DemoViewController {
}

- (void)dealloc {
demo_cleanup(&demo);
CVDisplayLinkRelease(_displayLink);
[self quit];
[super dealloc];
}

- (void)quit {
CVDisplayLinkRelease(_displayLink);
demo_cleanup(&demo);
}

/** Since this is a single-view app, initialize Vulkan during view loading. */
- (void)viewDidLoad {
[super viewDidLoad];
Expand Down
11 changes: 10 additions & 1 deletion cube/macOS/cubepp/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#import "AppDelegate.h"
#import "DemoViewController.h"

@interface AppDelegate ()

Expand All @@ -29,7 +30,15 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
NSApplication *app = aNotification.object;
NSArray<NSWindow *> *windows = app.windows;
for (NSUInteger i = 0; i < windows.count; ++i) {
NSViewController *viewController = windows[i].contentViewController;
if ([viewController isKindOfClass:[DemoViewController class]]) {
[(DemoViewController *)viewController quit];
break;
}
}
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
Expand Down
3 changes: 3 additions & 0 deletions cube/macOS/cubepp/DemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

/** The main view controller for the demo storyboard. */
@interface DemoViewController : NSViewController

- (void)quit;

@end

#pragma mark -
Expand Down
8 changes: 6 additions & 2 deletions cube/macOS/cubepp/DemoViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ @implementation DemoViewController {
}

- (void)dealloc {
demo.cleanup();
CVDisplayLinkRelease(_displayLink);
[self quit];
[super dealloc];
}

- (void)quit {
CVDisplayLinkRelease(_displayLink);
demo.cleanup();
}

/** Since this is a single-view app, initialize Vulkan during view loading. */
- (void)viewDidLoad {
[super viewDidLoad];
Expand Down

0 comments on commit 6149e30

Please sign in to comment.