浏览代码

UI: Destroy save timer before closing main window

This prevents the save timer from unexpectedly going off during the
middle of the save process.
jp9000 10 年之前
父节点
当前提交
c4ef2522ad
共有 2 个文件被更改,包括 10 次插入5 次删除
  1. 8 5
      obs/window-basic-main.cpp
  2. 2 0
      obs/window-basic-main.hpp

+ 8 - 5
obs/window-basic-main.cpp

@@ -653,15 +653,13 @@ void OBSBasic::OBSInit()
 	TimedCheckForUpdates();
 	loaded = true;
 
-	QTimer *timer = new QTimer(this);
-	connect(timer, SIGNAL(timeout()), this, SLOT(SaveProject()));
-	timer->start(20000);
+	saveTimer = new QTimer(this);
+	connect(saveTimer, SIGNAL(timeout()), this, SLOT(SaveProject()));
+	saveTimer->start(20000);
 }
 
 OBSBasic::~OBSBasic()
 {
-	SaveProject();
-
 	/* XXX: any obs data must be released before calling obs_shutdown.
 	 * currently, we can't automate this with C++ RAII because of the
 	 * delicate nature of obs_shutdown needing to be freed before the UI
@@ -1659,6 +1657,11 @@ void OBSBasic::closeEvent(QCloseEvent *event)
 	// remove draw callback in case our drawable surfaces go away before
 	// the destructor gets called
 	obs_remove_draw_callback(OBSBasic::RenderMain, this);
+
+	/* Delete the save timer so it doesn't trigger after this point while
+	 * the program data is being freed */
+	delete saveTimer;
+	SaveProject();
 }
 
 void OBSBasic::changeEvent(QEvent *event)

+ 2 - 0
obs/window-basic-main.hpp

@@ -61,6 +61,8 @@ private:
 
 	bool loaded = false;
 
+	QPointer<QTimer> saveTimer;
+
 	QPointer<OBSBasicInteraction> interaction;
 	QPointer<OBSBasicProperties> properties;
 	QPointer<OBSBasicTransform> transformWindow;