Browse Source

Prevent multiple Rack instances on Windows

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
6827b127ac
1 changed files with 14 additions and 0 deletions
  1. +14
    -0
      src/main.cpp

+ 14
- 0
src/main.cpp View File

@@ -15,6 +15,9 @@
#include "osdialog.h"
#include <unistd.h>

#ifdef ARCH_WIN
#include <Windows.h>
#endif

using namespace rack;

@@ -44,6 +47,17 @@ int main(int argc, char* argv[]) {
patchFile = argv[optind];
}

#ifdef ARCH_WIN
// Windows global mutex to prevent multiple instances
// Handle will be closed by Windows when the process ends
HANDLE instanceMutex = CreateMutex(NULL, true, gApplicationName.c_str());
if (GetLastError() == ERROR_ALREADY_EXISTS) {
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack is already running. Multiple Rack instances are not supported.");
exit(1);
}
(void) instanceMutex;
#endif

// Initialize environment
randomInit();
assetInit(devMode);


Loading…
Cancel
Save