From ea8f98b33960f1d8b3e05900362f9294b93b1686 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Fri, 18 Dec 2020 08:48:39 +0000 Subject: [PATCH] Wait for initialDrawCallback to finish before removing it --- apps/openmw/mwgui/loadingscreen.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index 9ab5e32a3f..5f0e9f33a3 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -1,6 +1,7 @@ #include "loadingscreen.hpp" #include +#include #include @@ -139,6 +140,7 @@ namespace MWGui public: CopyFramebufferToTextureCallback(osg::Texture2D* texture) : mTexture(texture) + , mOneshot(true) { } @@ -147,9 +149,25 @@ namespace MWGui 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); } private: + mutable bool mOneshot; + mutable std::mutex mMutex; + mutable std::condition_variable mSignal; osg::ref_ptr mTexture; }; @@ -375,7 +393,7 @@ namespace MWGui if (mCopyFramebufferToTextureCallback) { - + mCopyFramebufferToTextureCallback->wait(); #if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 10) mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback); #else