I have an OpenGLContext that is attached to a component, let’s call it MyComponent.
This component takes care of attaching and detaching the OpenGLContext in its constructor and destructor, respectively.
When destroying the component that contains the MyComponent instance at the application’s shutdown, I’m hitting the following assertion in juce_OpenGLContext.cpp:740:
void componentBeingDeleted (Component& c) override
{
/* You must call detach() or delete your OpenGLContext to remove it
from a component BEFORE deleting the component that it is using!
*/
jassertfalse;
ComponentMovementWatcher::componentBeingDeleted (c);
}
This doesn’t make a lot of sense to me, as the component c passed into this function is the parent component that contains the MyComponent which actually has the OpenGLContext bound. So why would the OpenGLContext complain here? Shouldn’t the assertion only be thrown when c is actually the component it’s bound to?
MyComponent’s destructor is only reached after the assertion was made. Anything I can do to fix this? Is this correct behaviour?
I do correctly free up any OpenGL resources in openGLContextClosing, that’s not the issue and not what triggers the assertion.
I also do detach the OpenGLContext in the destructor, just like you do - the only difference is that my OpenGLContext lives in a child component, not directly in the AudioProcessorEditor.
I found the culprit when hunting down a different bug - I had a shared_ptr to the MyComponent (the one that owns the OpenGLContext) hanging around for longer than its parent component, so naturally the parent component’s destructor would be called before that of MyComponent.