Browse Source

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
Palana 11 years ago
parent
commit
d56432304e
3 changed files with 21 additions and 2 deletions
  1. 7 2
      obs/window-basic-main.cpp
  2. 13 0
      obs/window-basic-properties.cpp
  3. 1 0
      obs/window-basic-properties.hpp

+ 7 - 2
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)

+ 13 - 0
obs/window-basic-properties.cpp

@@ -21,6 +21,7 @@
 #include "qt-wrappers.hpp"
 #include "display-helpers.hpp"
 
+#include <QCloseEvent>
 #include <QScreen>
 #include <QWindow>
 
@@ -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 = {};

+ 1 - 0
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;
 };