Hello! and Error: ...incorrectly used with a different GLContext...

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Hello! and Error: ...incorrectly used with a different GLContext...

LordSmoke
Hello, Folks! It has been a while. Two years, in fact, since I have been able to do any jogl programming. I only have blocks of time for immersive programming during my teaching visits to Vienna, and last year I had a bunch of lectures and workshops that precluded that.

However, my student, Lili, did a great job (with your generous help) of building a jogl API to my specs that I am now incorporating into my software package. I have almost all the tools to draw into a jogl canvas such that I can concentrate on the higher-level functions.

I do have one, I hope easily answered, question.

I have several JTabbedPane windows (random shapes, regression, principal components, etc.) with different GLCanvases within them. In one that I am using to familiarize myself has a simply timer that generates and plots random shapes in random sizes, locations, colors. Very robust, except that when I switch from on GLCanvas pane to another, the timer call to canvas.display() generates the error:

Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: This GL object is being incorrectly used with a different GLContext than that which created it on thread AWT-EventQueue-0

I am guessing I should save/reset the GLContext to the one for the particular window or canvas and this would only require a simple line or two of code if I knew what they were.

Comments? Suggestions?

TIA, LS
Reply | Threaded
Open this post in threaded view
|

Re: Hello! and Error: ...incorrectly used with a different GLContext...

gouessej
Administrator
Hi

Why not using a shared context?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Hello! and Error: ...incorrectly used with a different GLContext...

LordSmoke
gouessej wrote
Hi

Why not using a shared context?
Why not? I don't know about them. But if that is the direction I should be looking, I will do so.

The library is set up so I can just specify symbols, lines, text, etc., color, size, location, etc. and set rendering parameters just calling Lilis classes and isolating my work from the jogl nitty gritty. Lili never worked with multiple contexts, so it never came up for her.

So, I will begin my search and research.

Thanks, LS
Reply | Threaded
Open this post in threaded view
|

Re: Hello! and Error: ...incorrectly used with a different GLContext...

LordSmoke
In reply to this post by LordSmoke
Just to clarify the issue here is a screen shot of my application and the error. The RANDOM, RAND_2, RAND_3 are all instances of the RandomPlotPanel class that individually sets up the gl environment.

The error is generated by starting up with the RANDOM window selected, selecting RAND_2, and going back to RANDOM. Returning to the last, RAND_2, is still operating correctly.

These panels (when actually implemented) will be created and disposed of in any number and/or order.

The random panels are just for me to play with integrating the system into my software and working out the relationships between all the various classes which strive to isolate biological data (me) from details of the graphics (Lili).

So, should I still be looking at shared contexts?

Reply | Threaded
Open this post in threaded view
|

Re: Hello! and Error: ...incorrectly used with a different GLContext...

LordSmoke
In reply to this post by LordSmoke
It has been a while, and I have been working on this problem as time permits, so I think it is time to check in.

I have been reading OpenGL Programming Guide 8th Ed., but so far that seems mostly geared toward the actual plotting of things. That is working fine for me. My problem is with switching between JTabbedPane panels, and there seems to be precious little detail on the use of shared contexts.

I suspect my problem is a lack of theoretical understanding and not just a coding error, so any advice as to where to turn or sources of additional material, examples, etc on the use of shared contexts/autodrawables would be appreciated.

What I have done

(following https://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/GLSharedContextSetter.html)

is:

1) Created a class to generate a GLAutoDrawable and functions to return that and other things as required by the example code.

2) I then pass this into my panel constructor and use it with my GLCanvas constructor:

    public My_CanvasManager(My_SharedAutoDrawable sGLAD) {
        if (sGLAD==null) {
            GLCapabilities capabilities = new GLCapabilities(GLProfile.getMaxProgrammable(true));
            GLCapabilities(GLProfile.getMaxProgrammable(true));
            canvas = new GLCanvas(capabilities);
        } else {
            canvas = new GLCanvas(sGLAD.getGLCapabilities());
            canvas.setSharedAutoDrawable(sGLAD.getSharedAutoDrawable());
        }
       
3) I then set up a change listener for the JTabbedPane that then casts the value returned by getSelectedComponent(), queries if it has a GLCanvas, then calls a function to set the Shared AutoDrawable:

    jTabbedPane_MainPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            System.out.println("Tab: " + jTabbedPane_MainPane.getSelectedIndex());
            My_JPanel sljp = (My_JPanel)jTabbedPane_MainPane.getSelectedComponent();
            if (sljp.getHasGLCanvas()) {
                sljp.activateGL(sGLAD.getSharedAutoDrawable());
            }
        }
    });

All of this works fine moving from one new panel to the next, but backing up to one that was earlier selected gives me:

Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: This GL object is being incorrectly used with a different GLContext than that which created it on thread AWT-EventQueue-0

Might someone care to point me in the right direction?
Reply | Threaded
Open this post in threaded view
|

Re: Hello! and Error: ...incorrectly used with a different GLContext...

gouessej
Administrator
Only one GLContext must be current at a time and the GL object you use must match with the GLContext of the current GLAutoDrawable. I just hope that you don't store any GL instances in fields... Use GLContext.getCurrentGL() and GLContext.getCurrent(), you won't have any trouble or get them from your drawable. I can do nothing more with a SSCCE, a real SSCCE, not a piece of code which might miss the faulty part.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Hello! and Error: ...incorrectly used with a different GLContext...

LordSmoke
I don't want to waste your time looking at my code at this point. I need background, first, I think. Some links to tutorials or example code for using shared contexts to give me a bit of a theoretical grounding would be appreciated, if such exists. I find precious little searching for shared contexts and autodrawables.
Reply | Threaded
Open this post in threaded view
|

Re: Hello! and Error: ...incorrectly used with a different GLContext...

LordSmoke
In reply to this post by gouessej
Hmm, problem solved?

I tried writing a SSCCE program using some simple rotating triangle code from the internet inserted into tabbed pane panels, but it worked! In comparing the code sections (the internet and mine), the following line (where gl is a static variable) in my "display" function made the problem go away:

    @Override
    public void display(GLAutoDrawable drawable) {    
        gl = drawable.getGL().getGL3();
        ...  

The code worked without this line for a single glcanvas window, but switching between tabbed windows generated the error.

Does this make sense?
Reply | Threaded
Open this post in threaded view
|

Re: Hello! and Error: ...incorrectly used with a different GLContext...

gouessej
Administrator
Yes it makes sense. I have repeated numerous times that the GL instances can become invalid at any time. Therefore, a developer should never store them in any field or in global variables, (s)he should only store them into local variables with a limited scope and avoid passing them, (s)he should get it from a drawable or with GLContext.getCurrentGL(). If you look at the source code of the numerous renderers I have maintained for years, you'll see that I strictly follow these guidelines. Storing a GL instance into a (probably never updated) static variable is an excellent example of what shouldn't be done. Thank you for your feedback, it illustrates my advices.

Edit.: By the way, my latest advice in my previous post was correct. I just feel sad that you didn't understand it and I hope that now you see the importance of providing a SSCCE.
Julien Gouesse | Personal blog | Website