OpenGLContext::copyTexture causes crash with other drawing

When I use OpenGLContext::copyTexture and any paint() methods in the same app I get a crash.  I can reproduce this (using latest JUCE) when running on OSX and iOS - I haven't tested yet on other platforms.

To reproduce:

 * Set up new GUI project and set MainComponent to be an OpenGLRenderer and attach a context.

 * Add a child component that uses the Graphics methods in it's paint (i.e stroking a path).

 * Create OpenGLTextures when context is created

 * Copy OpenGLTexture in the draw method

I then get a crash in juce_OpenGLGraphicsContext line 1249 (glDrawElements).


I've written some of my own OpenGL to test what the cause is and found that calling

glBindBuffer(GL_ARRAY_BUFFER, vboID) 

glBindBuffer(GL_ARRAY_BUFFER, 0) 

will cause the crash

Just saying what you've done in that way doesn't really help - you could have made all kinds of mistakes that would cause a crash.. If you can post some code that actually reproduces the problem, we could take a look.

I've got this down to the minimum program that reliably crashes.  The MainContentComponent's header and implementation are attached in the .txt.

I'm calling OpenGLContext::copyTexture from the paint method which I believe I'm allowed to do?

My goal is to keep my own cache of textures and draw them using my own shaders.  Is this the right way to go about this?

Most probably not; issue it in renderOpenGL(). If you're using it in paint, use an OpenGLImageType instead.

It should not crash though.

You can't do openGL directly in paint() - at that point the juce rendering system doesn't expect you to mess around with the GL context state. Do your actual GL function calls only inside renderOpenGL, and in paint() just stick to juce Graphics commands.

What's the best way to use custom OpenGL in multiple different components?  

I guess I could subclass Component and add a renderGL() method then build my hierarchy from those.  I'd then probably have to write something to mark bits of the screen dirty unless I just constantly redraw everything.