From 6827b127acca7d5d99bd4ac23075dcbd080a2b10 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 31 Jul 2018 11:57:11 -0400 Subject: [PATCH] Prevent multiple Rack instances on Windows --- src/main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index a5562176..cd8a5ddf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,9 @@ #include "osdialog.h" #include +#ifdef ARCH_WIN + #include +#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);