From d56432304e6e8ae00ea66bef8c1847894e5cac9f Mon Sep 17 00:00:00 2001 From: Palana Date: Thu, 17 Apr 2014 17:18:51 +0200 Subject: [PATCH] Fix crash when closing windows via the X title bar button On OSX clicking the X title bar button immediately destroys "all" native windows (after sending a close event) which causes [NSSurface _disposeSurface] to crash if invoked while GL is using the surface --- obs/window-basic-main.cpp | 9 +++++++-- obs/window-basic-properties.cpp | 13 +++++++++++++ obs/window-basic-properties.hpp | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 68c3d129a..67e9773cb 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -539,8 +539,13 @@ void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy) void OBSBasic::closeEvent(QCloseEvent *event) { - /* TODO */ - UNUSED_PARAMETER(event); + QWidget::closeEvent(event); + if (!event->isAccepted()) + return; + + // remove draw callback in case our drawable surfaces go away before + // the destructor gets called + obs_remove_draw_callback(OBSBasic::RenderMain, this); } void OBSBasic::changeEvent(QEvent *event) diff --git a/obs/window-basic-properties.cpp b/obs/window-basic-properties.cpp index cbf4a67e1..7d21a8475 100644 --- a/obs/window-basic-properties.cpp +++ b/obs/window-basic-properties.cpp @@ -21,6 +21,7 @@ #include "qt-wrappers.hpp" #include "display-helpers.hpp" +#include #include #include @@ -109,6 +110,18 @@ void OBSBasicProperties::timerEvent(QTimerEvent *event) } } +void OBSBasicProperties::closeEvent(QCloseEvent *event) +{ + QDialog::closeEvent(event); + if (!event->isAccepted()) + return; + + // remove draw callback in case our drawable surfaces go away before + // the destructor gets called + obs_display_remove_draw_callback(display, + OBSBasicProperties::DrawPreview, this); +} + void OBSBasicProperties::Init() { gs_init_data init_data = {}; diff --git a/obs/window-basic-properties.hpp b/obs/window-basic-properties.hpp index 0ee633103..fd0fb5da6 100644 --- a/obs/window-basic-properties.hpp +++ b/obs/window-basic-properties.hpp @@ -52,4 +52,5 @@ public: protected: virtual void resizeEvent(QResizeEvent *event) override; virtual void timerEvent(QTimerEvent *event) override; + virtual void closeEvent(QCloseEvent *event) override; };