OpenGLComponent Init Assert

Hello.

I’m trying to use the OpenGLComponent, by adding it directly to the main window at the program initialization :

MyWindow::MyWindow() : DocumentWindow (...)
{
  setContentComponent(new MyOpenGLComponent());
}

I get an assert because the openGL context is not yet initialized :

void juce_updateOpenGLWindowPos (void* context, Component* owner, Component* topComp) { jassert (context != 0); ... }

here is the callstack stack :

juce_updateOpenGLWindowPos::juce_updateOpenGLWindowPos InternalGLContextHolder::juce_updateOpenGLWindowPos ComponentMovementWatcher::componentMovedOrResized ComponentMovementWatcher::componentParentHierarchyChanged Component::internalHierarchyChanged Component::addChildComponent Component::addAndMakeVisible ResizableWindow::setContentComponent

I guess the parent component needs to be showed or inited before adding the OpenGLComponent. I was wondering what is the right way to do it ? Is there any method where I may add the OpenglComponent to the window ?

I also tried this with the JuiceDemo by adding the code below to the ContentComp constructor and it produce the same assert :

    ContentComp (MainDemoWindow* mainWindow_) : ...
    {
        LookAndFeel::setDefaultLookAndFeel (&shinyLookAndFeel);
        invokeDirectly (showWidgets, true);
        showDemo (createOpenGLDemo(), BinaryData::opengldemo_cpp);
        currentDemoId = showOpenGL;
    }

Sorry if it’s an obvious question. I actualy search the forum, and it seems that the ComponentMovementWatcher is quite new in the 1.39., so maybe…

Thanks

Hmm. In fact, it might be as simple as just needing a check in openglcomponent.cpp before it calls juce_updateOpenGLWindowPos

[code] if (context != 0)
juce_updateOpenGLWindowPos (context, owner, topComp);

[/code]

I’ve never seen the problem because in my examples I normally create the opengl comp later on, but it’s a perfectly valid thing to do.

It works. Thanks !