diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 9c843e76a..f9c55d393 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -292,6 +292,9 @@ void initApp(int& argc, char** argv, bool doInitQSettings) void shutdownQtApp() { + // restore default message handler, otherwise Qt logging on + // shutdown crashes once sglog is killed + qInstallMessageHandler(nullptr); static_qApp.reset(); } @@ -334,6 +337,10 @@ void restartTheApp() QProcess proc; QStringList args; + // ensure we release whatever mutex/lock file we have in home, + // so the new instance runs in writeable mode + fgShutdownHome(); + #if defined(Q_OS_MAC) QDir dir(qApp->applicationDirPath()); // returns the 'MacOS' dir dir.cdUp(); // up to 'contents' dir diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 44b3b0a05..ce264a3ec 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -408,6 +408,10 @@ static SGPath platformDefaultDataPath() } #endif +#if defined(SG_WINDOWS) +static HANDLE static_fgHomeWriteMutex = nullptr; +#endif + bool fgInitHome() { SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath()); @@ -438,8 +442,8 @@ bool fgInitHome() // unreliable and causes false-positives. Instead, use a named // mutex. - HANDLE hMutex = CreateMutexA(nullptr, FALSE, "org.flightgear.fgfs.primary"); - if (hMutex == nullptr) { + static_fgHomeWriteMutex = CreateMutexA(nullptr, FALSE, "org.flightgear.fgfs.primary"); + if (static_fgHomeWriteMutex == nullptr) { printf("CreateMutex error: %d\n", GetLastError()); SG_LOG(SG_GENERAL, SG_POPUP, "Failed to create mutex for multi-app protection"); return false; @@ -488,6 +492,15 @@ bool fgInitHome() return result; } +void fgShutdownHome() +{ +#if defined(SG_WINDOWS) + if (static_fgHomeWriteMutex) { + CloseHandle(static_fgHomeWriteMutex); + } +#endif +} + static void createBaseStorageDirForAddons(const SGPath& exportDir) { SGPath addonStorageBasePath = exportDir / "Addons"; diff --git a/src/Main/fg_init.hxx b/src/Main/fg_init.hxx index cafba02c7..755222e3a 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -36,6 +36,7 @@ class SGPath; std::string fgBasePackageVersion(const SGPath& path); bool fgInitHome(); +void fgShutdownHome(); // Read in configuration (file and command line) int fgInitConfig ( int argc, char **argv, bool reinit );