removeFromDesktop, executeOnGLThread

Hi,
I writing here as I’m trying to figure out what’s the best way of handling this.

I have multiple OpenGL ‘sub-classes’ being called by my main class. (within proper OpenGL context)
When my parent is being destructed it calls
executeOnGLThread with blocking (so my destructor would wait).

It works well in Standalone, AU, VST, AAX.
But on VST3 I hit:

        jassertfalse; // you called execute AFTER you detached your openglcontext

Sadly, it seems there’s no way knowing we’re going to be destroyed since,

ComponentHelpers::releaseAllCachedImageResources (*this);

Is being called from removeFromDesktop() without ability to get notified ahead of being removed.

Am I missing something?

I fought that recently myself:

In the destructor of your class call shutdownOpenGL();. That will call detach and stop the openGL thread.
But it won’t destroy the resources yet.
Instead you get the callback shutdown(); where you can safely now destroy your resources e.g. OpenGLTextures.
The OpenGLContext will then be destroyed just normal when the base class goes out of scope.

Worked for me, hope it works for you too.

Do you mean openGLContextClosing()?

since I don’t see shutdownOpenGL() except in OpenGLAppComponent where it eventually ends up calling openGLContextClosing()

Ah right, I ended up using OpenGLAppComponent. I realised that it is not bound to App at all, you can have multiple ones.

Are you using OpenGLContext and OpenGLRenderer subclasses?
But I think you can easily mimic that flow.

1 Like

I have a ‘parent’ class which is an OpenGLRenderer that calls childrens which are being called by the parent class with its context (so there’s single context shared between children).