Skip to content

Commit 3fea1a7

Browse files
committed
frontend: Fix OAuth and dock state save corruption
When the app is quit on macOS, the underlying process is either triggered by an application-level "Quit" event or by a main window "close" event. If the application-level "Quit" event is the trigger, OBSBasic::saveAll is called twice: First by Qt's session manager (via OBSApp::commitData) and another time by the main window's close event handled by OBSBasic::closeWindow. However if the main window is closed first (and is the first to call "saveAll") the underlying OAuth data object is destroyed after the data has been saved. When the second "saveAll" call takes place, it encounters a "nullptr" for the auth object, which makes "Auth::Save" effectively remove any OAuth configuration from the settings file (undoing prior work). At the other end, if the application quits first, some dock windows might have been explicitly closed by Qt before the main window is closed and thus the second call to "saveAll" will overwrite valid browser dock state data with incomplete data (any dock that has been closed by Qt before will not be present in that data). Wrapping the code responsible for saving OAuth and browser dock state data in a "std::call_once" block should ensure that this data is only written once and by whoever gets to call "saveAll" first (at which point state data is still considered "complete").
1 parent 151097d commit 3fea1a7

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

frontend/widgets/OBSBasic.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <QThread>
6161
#include <QWidgetAction>
6262

63+
#include <mutex>
6364
#ifdef _WIN32
6465
#include <sstream>
6566
#endif
@@ -107,6 +108,10 @@ extern bool cef_js_avail;
107108
extern void DestroyPanelCookieManager();
108109
extern void CheckExistingCookieId();
109110

111+
namespace {
112+
std::once_flag saveOnceFlag;
113+
}
114+
110115
static void AddExtraModulePaths()
111116
{
112117
string plugins_path, plugins_data_path;
@@ -1849,16 +1854,19 @@ void OBSBasic::saveAll()
18491854
saveGeometry().toBase64().constData());
18501855
}
18511856

1852-
Auth::Save();
1853-
SaveProjectNow();
1857+
std::call_once(saveOnceFlag, [this]() {
1858+
Auth::Save();
1859+
SaveProjectNow();
18541860

1855-
config_set_string(App()->GetUserConfig(), "BasicWindow", "DockState", saveState().toBase64().constData());
1861+
config_set_string(App()->GetUserConfig(), "BasicWindow", "DockState",
1862+
saveState().toBase64().constData());
18561863

18571864
#ifdef BROWSER_AVAILABLE
1858-
if (cef) {
1859-
SaveExtraBrowserDocks();
1860-
}
1865+
if (cef) {
1866+
SaveExtraBrowserDocks();
1867+
}
18611868
#endif
1869+
});
18621870

18631871
config_set_int(App()->GetAppConfig(), "General", "LastVersion", LIBOBS_API_VER);
18641872
config_save_safe(App()->GetAppConfig(), "tmp", nullptr);

0 commit comments

Comments
 (0)