提交 49501be2 编写于 作者: J jp9000

UI: Fix potential deadlocks when saving

SaveProject calls obs functions that locks certain mutexes, and because
I made it so that SaveProject was being called inside of certain signal
handlers (which could already be locked in other mutexes), it could
cause a mutual deadlock with other threads.

This fix puts the main project saving code in to SaveProjectDeferred,
then pushes it on to the Qt message queue to safely save outside of
those locks.  It's a function that's perfectly safe to put on the
message queue because it will automatically be disabled in certain
circumstances where it would be unsafe to call, such as on shutdown.

This code will also make it so that the project will not needlessly be
saved more than once if the SaveProjectDeferred call was pushed multiple
times on to the queue.
上级 e30255fb
......@@ -1103,6 +1103,21 @@ void OBSBasic::SaveProject()
if (disableSaving)
return;
projectChanged = true;
QMetaObject::invokeMethod(this, "SaveProjectDeferred",
Qt::QueuedConnection);
}
void OBSBasic::SaveProjectDeferred()
{
if (disableSaving)
return;
if (!projectChanged)
return;
projectChanged = false;
const char *sceneCollection = config_get_string(App()->GlobalConfig(),
"Basic", "SceneCollectionFile");
char savePath[512];
......
......@@ -75,6 +75,7 @@ private:
bool loaded = false;
long disableSaving = 1;
bool projectChanged = false;
QPointer<QThread> updateCheckThread;
QPointer<QThread> logUploadThread;
......@@ -197,6 +198,7 @@ public slots:
void RecordingStart();
void RecordingStop(int code);
void SaveProjectDeferred();
void SaveProject();
private slots:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册