OpenGL error on setVisible(true) when before was setVisible(false)

opengl

#1

Hi,

I created openGL application in Visual Studio 2017 with newest Projucer. Is similar to example JUCE/OpenGLDemo. Unfortunately when I setVisible on false and again on true there is exception in method:

static void checkGLError (const char* file, const int line)
{
for (;:wink:
{
const GLenum e = glGetError();

    if (e == GL_NO_ERROR)
        break;

    // if the peer is not valid then ignore errors
    if (! checkPeerIsValid (OpenGLContext::getCurrentContext()))
        continue;

    DBG ("***** " << getGLErrorMessage (e) << "  at " << file << " : " << line);
    jassertfalse;
}

}

Message:
***** GL_INVALID_VALUE at d:\juce\modules\juce_opengl\opengl/juce_OpenGLContext.cpp : 244

Thank you for any ideas how to solve this problem :slight_smile:


#2

Can you share some code that reproduces exactly the problem? It will depend how and where you’re calling setVisible


#3

I have class which inherits public Component, private OpenGLRenderer and implements:

void FiltersContentComponent::newOpenGLContextCreated()
{
if (shader.createShader(openGLContext))
{
// ================= Attributes =================
attributes = new Attributes(openGLContext, shader.getShader(),

	// ================= Uniforms =================== 
	uniforms = new Uniforms(openGLContext, shader.getShader());
}

}

void FiltersContentComponent::openGLContextClosing()
{
//empty
}

void FiltersContentComponent::renderOpenGL()
{
jassert(OpenGLHelpers::isContextActive());

  OpenGLHelpers::clear(Colour::greyLevel(0.1f));
 //and so on

}

void FiltersContentComponent::initOpenGL()
{
setOpaque(true);
openGLContext.setRenderer(this);
openGLContext.attachTo(*this);
openGLContext.setContinuousRepainting(true);
}

void FiltersContentComponent::deInitOpenGL()
{
setOpaque(false);
openGLContext.detach();
openGLContext.setRenderer(nullptr);
openGLContext.setContinuousRepainting(false);
}

And on this class I call:

virtual void closeButtonPressed() override
{
filtersContentComponent.deInitOpenGL();
setVisible(false);

}

// when I want to show this window
void show()
{
setVisible(true);
filtersContentComponent.initOpenGL();
}

So at first time when I click on button and call method show() everything is great, but when I closs window and click again button to show() I have exception.


#4

Ok, solved :smiley: The problem was with shader and attributes. I didn’t deleteing them after closing OpenGL and creating again on init OpenGL.

Enough was sth like that on setVisible(true):

shader = new Shader{};

if (shader->createShader(openGLContext))
{
// ================= Attributes =================
attributes = new Attributes(openGLContext, shader->getShader(),
CustomVertex::Cube::ROW_SIZE);

// ================= Uniforms =================== 
uniforms = new Uniforms(openGLContext, shader->getShader());

}

Thanks for your will to help :slight_smile: