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.
fix-osga-rotate-wildly
AnyOldName3 2 years ago committed by AnyOldName3
parent 53afa6b185
commit ec4731d454

@ -4,16 +4,29 @@ namespace SceneUtil
{ {
namespace 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() osg::GLExtensions& getGLExtensions()
{ {
if (!sGLExtensions) if (sGLExtensions.empty())
throw std::runtime_error( throw std::runtime_error(
"GetGLExtensionsOperation was not used when the current context was created or there is no current " "GetGLExtensionsOperation was not used when the current context was created or there is no current "
"context"); "context");
return *sGLExtensions; return **sGLExtensions.begin();
} }
GetGLExtensionsOperation::GetGLExtensionsOperation() GetGLExtensionsOperation::GetGLExtensionsOperation()
@ -23,6 +36,7 @@ namespace SceneUtil
void GetGLExtensionsOperation::operator()(osg::GraphicsContext* graphicsContext) 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…
Cancel
Save