From 27ba216271a8e36f521183f042c5b8c0dcc4d2e1 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Tue, 14 Feb 2023 19:42:41 +0100 Subject: [PATCH] libobs-opengl: Fix projector crash with external macOS displays When an external display is disconnected with a fullscreen projector attached to it, Qt will trigger a resize of the window twice, which makes the renderer queue 2 resize event blocks. At the time when those blocks are run, Qt's window destructor will have reset all pointers, and the block directly accesses pointers within structures identified by pointers, which are invalid by that point. This commit makes a block return early if the associated window has been destroyed already and also explicitly checks for valid pointers after. --- libobs-opengl/gl-cocoa.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libobs-opengl/gl-cocoa.m b/libobs-opengl/gl-cocoa.m index a3c19ca10..12dac2513 100644 --- a/libobs-opengl/gl-cocoa.m +++ b/libobs-opengl/gl-cocoa.m @@ -228,6 +228,10 @@ void gl_update(gs_device_t *device) NSOpenGLContext *parent = device->plat->context; NSOpenGLContext *context = swap->wi->context; dispatch_async(dispatch_get_main_queue(), ^() { + if (!swap || !swap->wi) { + return; + } + CGLContextObj parent_obj = [parent CGLContextObj]; CGLLockContext(parent_obj);