diff --git a/RESTService/addon.cc b/RESTService/addon.cc index 5e4eb2f0a..4463aa444 100644 --- a/RESTService/addon.cc +++ b/RESTService/addon.cc @@ -254,9 +254,14 @@ namespace minsky void drawNativeWindows() { + decltype(nativeWindowsToRedraw) windows; + { + const lock_guard lock(nativeWindowsToRedrawMutex); + windows.swap(nativeWindowsToRedraw); + } const lock_guard lock(minskyCmdMutex); const Timer timer(timers["draw"]); - for (auto i: nativeWindowsToRedraw) + for (auto i: windows) try { i->draw(); @@ -268,7 +273,6 @@ namespace minsky break; } catch (...) {break;} - nativeWindowsToRedraw.clear(); } // arrange for native window drawing to happen on node's main thread, required for MacOSX. @@ -284,12 +288,11 @@ namespace minsky const Timer timer(timers["draw"]); decltype(nativeWindowsToRedraw) windows; { - const lock_guard lock(minskyCmdMutex); + const lock_guard lock(nativeWindowsToRedrawMutex); windows.swap(nativeWindowsToRedraw); } for (auto i: windows) macOSXRedraw(*i,minskyCmdMutex); - nativeWindowsToRedraw.clear(); drawLaunched=false; } @@ -336,8 +339,12 @@ namespace minsky catch (...) {flags&=~reset_needed;} #ifdef MAC_OSX_TK - if (!drawLaunched && nativeWindowsToRedraw.size()) - macOSXLaunchDrawNativeWindows(); + if (!drawLaunched) + { + const lock_guard lock(nativeWindowsToRedrawMutex); + if (nativeWindowsToRedraw.size()) + macOSXLaunchDrawNativeWindows(); + } #else drawNativeWindows(); #endif diff --git a/model/minsky.h b/model/minsky.h index 89aaea4c9..4ae0297b9 100644 --- a/model/minsky.h +++ b/model/minsky.h @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -102,6 +103,7 @@ namespace minsky MinskyExclude& operator=(const MinskyExclude&) {return *this;} /// record nativeWindows that have requested redrawing + std::mutex nativeWindowsToRedrawMutex; std::set nativeWindowsToRedraw; protected: diff --git a/model/renderNativeWindow.cc b/model/renderNativeWindow.cc index a7ad783c9..00c4059c6 100644 --- a/model/renderNativeWindow.cc +++ b/model/renderNativeWindow.cc @@ -73,6 +73,7 @@ namespace minsky RenderNativeWindow::~RenderNativeWindow() { + const lock_guard lock(minsky().nativeWindowsToRedrawMutex); minsky().nativeWindowsToRedraw.erase(this); } @@ -106,6 +107,7 @@ void macOSXRedraw(RenderNativeWindow& window,std::recursive_mutex& cmdMutex) void RenderNativeWindow::requestRedraw() { if (!winInfoPtr.get()) return; + const lock_guard lock(minsky().nativeWindowsToRedrawMutex); minsky().nativeWindowsToRedraw.insert(this); }