diff options
author | Nadia Holmquist Pedersen <nadia@nhp.sh> | 2023-12-22 01:35:45 +0100 |
---|---|---|
committer | Nadia Holmquist Pedersen <nadia@nhp.sh> | 2023-12-22 01:35:45 +0100 |
commit | 752b37ed824ceb521f61f1a0c79b022efd9cef12 (patch) | |
tree | 14a2944f1ef3c8dbe351d99840b19839def28640 /src | |
parent | 084747abc52b22ace7ae02b895b343a789af7c67 (diff) |
Attempt to get rid of leftover QSharedMemory instance after crash
Diffstat (limited to 'src')
-rw-r--r-- | src/frontend/qt_sdl/Platform.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 4630582..6fe87ac 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -66,12 +66,25 @@ void IPCInit() IPCBuffer = new QSharedMemory("melonIPC"); +#if !defined(Q_OS_WINDOWS) + // QSharedMemory instances can be left over from crashed processes on UNIX platforms. + // To prevent melonDS thinking there's another instance, we attach and then immediately detach from the + // shared memory. If no other process was actually using it, it'll be destroyed and we'll have a clean + // shared memory buffer after creating it again below. + if (IPCBuffer->attach()) + { + IPCBuffer->detach(); + delete IPCBuffer; + IPCBuffer = new QSharedMemory("melonIPC"); + } +#endif + if (!IPCBuffer->attach()) { Log(LogLevel::Info, "IPC sharedmem doesn't exist. creating\n"); if (!IPCBuffer->create(1024)) { - Log(LogLevel::Error, "IPC sharedmem create failed :(\n"); + Log(LogLevel::Error, "IPC sharedmem create failed: %s\n", IPCBuffer->errorString().toStdString().c_str()); delete IPCBuffer; IPCBuffer = nullptr; return; |