mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 08:15:37 +00:00
Cope with scene widgets being destroyed in a weird order
I can't actually test this as the CS still doesn't get far enough with this MR.
This commit is contained in:
parent
53afa6b185
commit
ec4731d454
1 changed files with 18 additions and 4 deletions
|
@ -4,16 +4,29 @@ namespace SceneUtil
|
|||
{
|
||||
namespace
|
||||
{
|
||||
osg::observer_ptr<osg::GLExtensions> sGLExtensions;
|
||||
std::set<osg::observer_ptr<osg::GLExtensions>> sGLExtensions;
|
||||
|
||||
class GLExtensionsObserver : public osg::Observer
|
||||
{
|
||||
public:
|
||||
static GLExtensionsObserver sInstance;
|
||||
|
||||
void objectDeleted(void* referenced) override
|
||||
{
|
||||
sGLExtensions.erase(static_cast<osg::GLExtensions*>(referenced));
|
||||
}
|
||||
};
|
||||
|
||||
GLExtensionsObserver GLExtensionsObserver::sInstance{};
|
||||
}
|
||||
|
||||
osg::GLExtensions& getGLExtensions()
|
||||
{
|
||||
if (!sGLExtensions)
|
||||
if (sGLExtensions.empty())
|
||||
throw std::runtime_error(
|
||||
"GetGLExtensionsOperation was not used when the current context was created or there is no current "
|
||||
"context");
|
||||
return *sGLExtensions;
|
||||
return **sGLExtensions.begin();
|
||||
}
|
||||
|
||||
GetGLExtensionsOperation::GetGLExtensionsOperation()
|
||||
|
@ -23,6 +36,7 @@ namespace SceneUtil
|
|||
|
||||
void GetGLExtensionsOperation::operator()(osg::GraphicsContext* graphicsContext)
|
||||
{
|
||||
sGLExtensions = graphicsContext->getState()->get<osg::GLExtensions>();
|
||||
auto [itr, _] = sGLExtensions.emplace(graphicsContext->getState()->get<osg::GLExtensions>());
|
||||
(*itr)->addObserver(&GLExtensionsObserver::sInstance);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue