AWTGLCanvas and context

Started by Pogomon, January 06, 2006, 12:03:17

Previous topic - Next topic

Pogomon

Hey all,

I am using LWJGL to do visiualisation, and just moved the project from the Display class to using the AWTGLCanvas class for display. The problem I have is that it seems that every time the AWTGLCanvas is hidden (i.e.setVisible() is called on the Frame containing the canvas) the context gets destroyed which results in a loss of all the textures. This means I have to reload all the textures everytime the user reopens the display window.

Is there a way around this ?

Thanks

elias

Not that I know of. We're forced to destroy the context on hide, since Java is free to destroy the Frame and re-create it with a different setup.

- elias

princec

Use a pbuffer and shared context.

Cas :)

renanse

In regards to context, if an exception occurs during paint, the context is never released and subsequent paint calls throw an exception like:

java.lang.IllegalStateException: From thread Thread[AWT-EventQueue-0,6,main]: Thread[AWT-EventQueue-0,6,main] already has the context current
	at org.lwjgl.opengl.Context.checkAccess(Context.java:169)
	at org.lwjgl.opengl.Context.makeCurrent(Context.java:176)
	at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:251)
	at org.lwjgl.opengl.AWTGLCanvas.update(AWTGLCanvas.java:269)
	at sun.awt.RepaintArea.updateComponent(Unknown Source)
	at sun.awt.RepaintArea.paint(Unknown Source)
	at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)


Which of course happens over and over and over until I kill the app.

I can catch that with Thread.setDefaultUncaughtExceptionHandler(...) but it looks like I can not do anything to fix the problem (such as manually releasing the Context so subsequent paint calls don't trip up) given that Context is not externally accessible.  Perhaps paint itself should detect and fix the problem?  (eg. Oh, I already have the context, so I will just continue on my way.)  Ideas?

Fool Running

Quoten regards to context, if an exception occurs during paint, the context is never released and subsequent paint calls throw an exception...

Hmmmmm... That sounds bad :D

Unfortunatly, I don't have any ideas, but it certainly sounds worth fixing.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Matzon


elias

That's an odd exception. Can you  post the exception+trace that causes this situation (I assume it's the exception just before the IllegalStateException) in addition to the OS and the lwjgl version. A minimal test program would be nice too.

- elias

elias

I've applied a workaround that simple makes the context current and releases it every frame. That will also make the AWTGLCanvas more compliant with AWT which is allowed to use different threads to call paint().

- elias

Evil-Devil

Quote from: "elias"I've applied a workaround that simple makes the context current and releases it every frame. That will also make the AWTGLCanvas more compliant with AWT which is allowed to use different threads to call paint().

- elias
Does that not slow down the rendering?

elias

It does, but with a constant amount, so it shouldn't matter much at reasonable frame rates.

- elias

renanse

Sorry, was out there for a bit.  Good to hear about the "fix".  For completeness:  The exception causing it was really anything in paint.  For example, an NPE in my opengl code.  It happens on any OS I've tried it on and lwjgl version is .99 official.

Looking forward to a new official release (since that's all we use at jme :-/ )

elias

I sort of reproduced the problem here. I got this exception:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: From thread Thread[AWT-EventQueue-0,6,main]: Thread[AWT-EventQueue-0,6,] already has the context current


which is actually two different threads as expected (notice the missing "main" in the second thread name). I'm not sure how your exception came about (maybe an earlier version of lwjgl caused that, I don't know). Anyway, the fix works fine here.

- elias

renanse

Cool, when do we get that in a release?  :)

Matzon


Sormuras

Gogogo! It'd be great... :D