GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

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

GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

stepasite
Hi,

I am migrating from JOGL to JOGL2, but my code does not work with JOGL2.

I use my own class for rendering, it is descendant of GLCanvas. Here is the code which produces GLException:

public void addNotify()
{
  super.addNotify();
  GLContext context = getContext();
  context.makeCurrent(); // GLException is thrown
}

When my component is added to hierarchy (addNotify() is invoked on EDT), attempt to make a context current does not suffice, but GLException "Unable to create temp OpenGL context for device context" is thrown.

Removing the line:

context.makeCurrent()

from the source code does help, but I can't do this because of GLContext sharing (if multiple instances of my rendering class exist, the context is not shared when the line above is commented).

Does anyone struggle with the similar problem? Any help much or proposed solution much appreciated.

Thanks is advance,
Pavel

Reply | Threaded
Open this post in threaded view
|

Re: GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

Sven Gothel
Administrator
On 09/10/2012 05:26 PM, stepasite [via jogamp] wrote:

> Hi,
>
> I am migrating from JOGL to JOGL2, but my code does not work with JOGL2.
>
> I use my own class for rendering, it is descendant of GLCanvas. Here is the
> code which produces GLException:
>
> public void addNotify()
> {
>   super.addNotify();
>   GLContext context = getContext();
>   context.makeCurrent(); // GLException is thrown
> }
>
The lifecycle has changed dramatically.
JOGL2's GLAutoDrawable implementations (incl. GLCanvas)
use lazy initialization at the latest possible time
_and_ only when the native object is actually ready to be displayed.
The latter requires a valid size for example ..

Pls read the source ..

Deriving from a heavily specialized class like GLCanvas
is not advised and your mileage may vary (impl. changes).

A new proper way to impl. your own GLAutoDrawable
is to derive from GLAutoDrawableBase or to use GLAutoDrawableDelegate.
(GLWindow uses this approach for example)

There are unit tests demonstrating the above.

I am almost done w/ my 2-3 weeks rework to natively support
FBO drawable and auto-drawable, incl the offscreen layer mode for OSX.
When this work is pushed, you may like to look at the new unit tests.

~Sven



signature.asc (907 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

gouessej
Administrator
In reply to this post by stepasite
Hi

Sven is right, just see how I ported Ardor3D from JOGL 1.1.1a to JOGL 2.0, I had similar problems and I fixed them all

Try to get the context later, look at JoglAwtCanvas in Ardor3D.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

stepasite
Hi,

thanks for the info. Anyway, I am little bit confused how sharing of contexts should look like.

Yes, I can store context for sharing e.g. in init() handler, but when I want to share contexts between more canvases before they are displayed, I cannot see a way how to do it.

Also when moving canvases in the hierarchy (removing and adding them from/to a container) can possibly destroy all existing contexts which means that sharing won't suffice and textures, display lists, etc. will be destroyed.

Summed up: exists there a way how to create a context that can be seamlessly used for sharing between multiple GLCanvas instances?
Reply | Threaded
Open this post in threaded view
|

Re: GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

Sven Gothel
Administrator
On 09/11/2012 05:46 PM, stepasite [via jogamp] wrote:

> Hi,
>
> thanks for the info. Anyway, I am little bit confused how sharing of contexts
> should look like.
>
> Yes, I can store context for sharing e.g. in init() handler, but when I want
> to share contexts between more canvases before they are displayed, I cannot
> see a way how to do it.
>
> Also when moving canvases in the hierarchy (removing and adding them from/to a
> container) can possibly destroy all existing contexts which means that sharing
> won't suffice and textures, display lists, etc. will be destroyed.
>
> Summed up: exists there a way how to create a context that can be seamlessly
> used for sharing between multiple GLCanvas instances?
Shure .. there is a GLCanvas constructor taking a shared GLContext as an argument.

GLWindow is a bit different, is provides 'setSharedContext(GLContext)'
to avoid explosion of possible constructors etc.

If you like to share things between many GL context,
simple share the 'root' shared one with all of them. Should work.

~Sven



signature.asc (907 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

stepasite
Hi Sven,

I know about the constructor and that was the way how I shared GLContext instances till migrating  to JOGL2.

But with JOGL2 this sharing does not work reliably for me. When all the canvases are docked in my app at the same time (removeNotify() and then addNotify() called for all the canvases), the context is sometimes lost.

Maybe I do someting wrong. I will recheck my app logic and life-cycle of GLContext resources. I hopefully find what changes cause problems in my code.

When asking my previous question, I was looking for a way of sharing GLContext as it is done in GLWindow -- sharing of context can be done later (e.g. in init()), not when constructing an object.

Thanks for your help,
Pavel
Reply | Threaded
Open this post in threaded view
|

Re: GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

Sven Gothel
Administrator
On 09/11/2012 09:02 PM, stepasite [via jogamp] wrote:
> Hi Sven,
>
> I know about the constructor and that was the way how I shared GLContext
> instances till migrating  to JOGL2.
>
> But with JOGL2 this sharing does not work reliably for me. When all the
> canvases are docked in my app at the same time (removeNotify() and then
> addNotify() called for all the canvases), the context is sometimes lost.

Right .. use an offscreen drawable / GLContext and share that one
w/ the other. See *Shared* unit tests ..

>
> When asking my previous question, I was looking for a way of sharing GLContext
> as it is done in GLWindow -- sharing of context can be done later (e.g. in
> init()), not when constructing an object.

nope .. in GLWindow and all GLContext usage in general (native API general)
it has to be done before the GLContext is constructed
and hence before any GLEventListener gets called.

~Sven



signature.asc (907 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

stepasite
Hi Sven,

using an offscreen drawable did help. First the drawable is created, then context on it which is shared later on.

 I haven't found any remarks about offscreen drawable restrictions (only hardware opengl, etc.) so I think this solution will work.

Anyway, I have found a remark about context sharing limitations, but I guess that context sharing will work on most platforms without any problems (as it did in JOGL 1.1).

Thanks for your help,
Pavel
Reply | Threaded
Open this post in threaded view
|

Re: GLException "Unable to create temp OpenGL context for device context" thrown when GLContext.makeCurrent() called

gouessej
Administrator
Keep in mind that context sharing does not work very well with some low end chips, some drivers under Windows don't even accept the context creation or manipulation from threads (especially the latter).
Julien Gouesse | Personal blog | Website