From f0809a667fe1369809233589e17455d9599f4804 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 19 Jul 2019 15:50:36 +0300 Subject: [PATCH] Fixed a potential Cocoa crash when closing a window --- Cocoa/Document.m | 1 + Cocoa/GBViewMetal.m | 1 + 2 files changed, 2 insertions(+) diff --git a/Cocoa/Document.m b/Cocoa/Document.m index b99e4c8..a520d62 100644 --- a/Cocoa/Document.m +++ b/Cocoa/Document.m @@ -389,6 +389,7 @@ static void audioCallback(GB_gameboy_t *gb, GB_sample_t *sample) - (void)dealloc { [cameraSession stopRunning]; + self.view.gb = NULL; GB_free(&gb); if (cameraImage) { CVBufferRelease(cameraImage); diff --git a/Cocoa/GBViewMetal.m b/Cocoa/GBViewMetal.m index 9acb11e..94b4975 100644 --- a/Cocoa/GBViewMetal.m +++ b/Cocoa/GBViewMetal.m @@ -131,6 +131,7 @@ static const vector_float2 rect[] = - (void)drawInMTKView:(nonnull MTKView *)view { if (!(view.window.occlusionState & NSWindowOcclusionStateVisible)) return; + if (!self.gb) return; if (texture.width != GB_get_screen_width(self.gb) || texture.height != GB_get_screen_height(self.gb)) { [self allocateTextures];