diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 772af3759e..bbe4f25f69 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -875,7 +875,14 @@ public: void join() { if (mThread) + { + { + std::lock_guard lk(mMutex); + mJoinRequest = true; + } + mCV.notify_one(); mThread->join(); + } } private: @@ -891,10 +898,12 @@ private: void threadBody() { - while (!mEngine->mViewer->done() && !mEngine->mEnvironment.getStateManager()->hasQuitRequest()) + while (true) { std::unique_lock lk(mMutex); - mCV.wait(lk, [&]{ return mUpdateRequest; }); + mCV.wait(lk, [&]{ return mUpdateRequest || mJoinRequest; }); + if (mJoinRequest) + break; update(); @@ -908,6 +917,7 @@ private: std::mutex mMutex; std::condition_variable mCV; bool mUpdateRequest = false; + bool mJoinRequest = false; double mDt = 0; bool mIsGuiMode = false; std::optional mThread;