I have a very simple app that is displaying an image in an OpenGLRenderer object. I get an assert on destroying the component and was hoping someone could tell me what I was doing wrong.
The assertion is in JUCE Assertion failure in opengl/juce_OpenGLTexture.cpp:164.
This is the class which will cause an assertion when deleting this component
class OGLTestComponent : public OpenGLRenderer, public Component
{
public:
OGLTestComponent() {
context.attachTo(*this);
context.setRenderer(this);
context.setContinuousRepainting(true);
}
~OGLTestComponent() {
context.detach();
}
virtual void paint(Graphics& g) {
}
virtual void newOpenGLContextCreated() {
img = Image(Image::PixelFormat::ARGB, getBounds().getWidth(), getBounds().getHeight(), true);
}
virtual void renderOpenGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Create an OpenGLGraphicsContext that will draw into this GL window..
ScopedPointer<LowLevelGraphicsContext> glRenderer(createOpenGLGraphicsContext(context, getWidth(), getHeight()));
if (glRenderer != nullptr)
{
if (img.isValid())
{
Graphics g(*glRenderer);
g.drawImage(img, getLocalBounds().toFloat());
}
}
};
virtual void openGLContextClosing() {
img = Image::null;
}
Image img;
OpenGLContext context;
};