Make OpenGLComponent::deleteContext protected or public


#1

Hi,

I’m running my application under a GL debugger, and I’ve resource leaks. The resource leaks are due to the fact that I’m using a thread to render OpenGL stuff.
Unfortunately I must send huge textures to the card, and these leaks accumulate each time I start the component.
I’m creating a context in that thread, but I can’t delete it.
So when the OpenGLComponent destructor is called on the message thread, it’s calling deleteContext which is not functionnal since the context was only valid for the other (finished) thread.

So, I think we need a way to delete a context in the same thread as it was created.
This can be done easily if OpenGLComponent::deleteContext was public (or at worst protected, but this would imply useless subclassing).

What do you think ?


#2

Good idea, I’ve no objection to making that public, as the context gets recreated on demand anyway, so being able to clear it might be useful for many reasons. I’ll make that change in the next check-in.


#3

Hi !
First, thank you so for all the amazing job you’re doing, I really do appreciate !

Then, a little suggestion : while you are at modifying OpenGLComponent’s code, why don’t you also override OpenGLComponent::visibiltyChanged() into that would actually make the OpenGLComponent to actually disappear when when setVisible(false) is called ?

virtual void OpenGLComponent::visibilityChanged()
{
	if(isVisible())
		deleteContext();
	else
		makeCurrentContextActive();
};

For now, I am overriding it mannually, but I feel it could be helpful to others.
Thanks in advance !

Valentin


#4

Thanks - I’m surprised it doesn’t already handle that!

Good request, but that’s probably the wrong way to do it - I think a better way would be just to update this existing function, in OpenGLComponent::OpenGLComponentWatcher

[code] void componentVisibilityChanged (Component&)
{
const bool isShowingNow = owner->isShowing();

    if (wasShowing != isShowingNow)
    {
        wasShowing = isShowingNow;
        
        if (! isShowingNow)
        {
            const ScopedLock sl (owner->getContextLock());
            owner->deleteContext();
        }
    }
}

[/code]

…I’ve not tried this, but I don’t think there’s any need to re-create the context when the comp becomes visible, as the repaint call should make that happen.


#5

Hi !

I just tried it : it works just fine. Thank you again !

Val