From 663e0a10551fbd394d27aa4aa31321cda88b382b Mon Sep 17 00:00:00 2001 From: madsbuvi Date: Tue, 26 Jan 2021 19:28:09 +0100 Subject: [PATCH] Fix a race condition in loading screen. --- apps/openmw/mwgui/loadingscreen.cpp | 49 ++--------------------------- apps/openmw/mwgui/loadingscreen.hpp | 2 -- 2 files changed, 2 insertions(+), 49 deletions(-) diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index 7ddc8c5507..aeaacaa638 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -45,8 +45,6 @@ namespace MWGui , mNestedLoadingCount(0) , mProgress(0) , mShowWallpaper(true) - , mOldCallback(nullptr) - , mHasCallback(false) { mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize()); @@ -147,35 +145,11 @@ namespace MWGui void operator () (osg::RenderInfo& renderInfo) const override { - { - std::unique_lock lock(mMutex); - mOneshot = false; - } - mSignal.notify_all(); - int w = renderInfo.getCurrentCamera()->getViewport()->width(); int h = renderInfo.getCurrentCamera()->getViewport()->height(); mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h); - { - std::unique_lock lock(mMutex); - mOneshot = false; - } - mSignal.notify_all(); - } - - void wait() - { - std::unique_lock lock(mMutex); - while (mOneshot) - mSignal.wait(lock); - } - - void waitUntilInvoked() - { - std::unique_lock lock(mMutex); - while (mOneshot) - mSignal.wait(lock); + mOneshot = false; } void reset() @@ -185,8 +159,6 @@ namespace MWGui private: mutable bool mOneshot; - mutable std::mutex mMutex; - mutable std::condition_variable mSignal; osg::ref_ptr mTexture; }; @@ -362,14 +334,12 @@ namespace MWGui } #if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 10) + mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback); mViewer->getCamera()->addInitialDrawCallback(mCopyFramebufferToTextureCallback); #else - // TODO: Remove once we officially end support for OSG versions pre 3.5.10 - mOldCallback = mViewer->getCamera()->getInitialDrawCallback(); mViewer->getCamera()->setInitialDrawCallback(mCopyFramebufferToTextureCallback); #endif mCopyFramebufferToTextureCallback->reset(); - mHasCallback = true; mBackgroundImage->setBackgroundImage(""); mBackgroundImage->setVisible(false); @@ -412,21 +382,6 @@ namespace MWGui mViewer->renderingTraversals(); mViewer->advance(mViewer->getFrameStamp()->getSimulationTime()); - if (mHasCallback) - { - mCopyFramebufferToTextureCallback->waitUntilInvoked(); - - // Note that we are removing the callback before the draw thread has returned from it. - // This is OK as we are retaining the ref_ptr. -#if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 10) - mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback); -#else - // TODO: Remove once we officially end support for OSG versions pre 3.5.10 - mViewer->getCamera()->setInitialDrawCallback(mOldCallback); -#endif - mHasCallback = false; - } - mLastRenderTime = mTimer.time_m(); } diff --git a/apps/openmw/mwgui/loadingscreen.hpp b/apps/openmw/mwgui/loadingscreen.hpp index 5d86ed3896..e1c652386d 100644 --- a/apps/openmw/mwgui/loadingscreen.hpp +++ b/apps/openmw/mwgui/loadingscreen.hpp @@ -87,8 +87,6 @@ namespace MWGui osg::ref_ptr mTexture; osg::ref_ptr mCopyFramebufferToTextureCallback; - osg::ref_ptr mOldCallback; - bool mHasCallback; std::unique_ptr mGuiTexture; void changeWallpaper();