diff --git a/apps/openmw/mwgui/debugwindow.cpp b/apps/openmw/mwgui/debugwindow.cpp index d5b703d1fb..23c8dbfe2e 100644 --- a/apps/openmw/mwgui/debugwindow.cpp +++ b/apps/openmw/mwgui/debugwindow.cpp @@ -8,6 +8,8 @@ #include #include +#include + #ifndef BT_NO_PROFILE namespace @@ -103,9 +105,10 @@ namespace MWGui #endif } - std::vector DebugWindow::sLogCircularBuffer; - int64_t DebugWindow::sLogStartIndex = 0; - int64_t DebugWindow::sLogEndIndex = 0; + static std::vector sLogCircularBuffer; + static std::mutex sBufferMutex; + static int64_t sLogStartIndex; + static int64_t sLogEndIndex; void DebugWindow::startLogRecording() { @@ -125,6 +128,7 @@ namespace MWGui default: color = "#FFFFFF"; } bool bufferOverflow = false; + std::lock_guard lock(sBufferMutex); const int64_t bufSize = sLogCircularBuffer.size(); auto addChar = [&](char c) { @@ -153,6 +157,8 @@ namespace MWGui void DebugWindow::updateLogView() { + std::lock_guard lock(sBufferMutex); + if (!mLogView || sLogCircularBuffer.empty() || sLogStartIndex == sLogEndIndex) return; if (mLogView->isTextSelection()) @@ -161,8 +167,6 @@ namespace MWGui std::string addition; const int64_t bufSize = sLogCircularBuffer.size(); { - // Log object is only required for locking at this point. - Log log(Debug::Debug); if (sLogStartIndex < sLogEndIndex) addition = std::string(sLogCircularBuffer.data() + sLogStartIndex, sLogEndIndex - sLogStartIndex); else diff --git a/apps/openmw/mwgui/debugwindow.hpp b/apps/openmw/mwgui/debugwindow.hpp index dba7436bc3..9b8711137a 100644 --- a/apps/openmw/mwgui/debugwindow.hpp +++ b/apps/openmw/mwgui/debugwindow.hpp @@ -20,13 +20,7 @@ namespace MWGui void updateBulletProfile(); MyGUI::TabControl* mTabControl; - MyGUI::EditBox* mLogView; - - static std::vector sLogCircularBuffer; - static int64_t sLogStartIndex; - static int64_t sLogEndIndex; - MyGUI::EditBox* mBulletProfilerEdit; };