Can not start a second context

Hi Guys!



I have a Swing application with a canvas (works fine) to display models from a database.

Now I’m trying to integrate my model importer (works well from command line) that uses a SceneProcessor to render thumbnails of the models in OffscreenSurface mode.

Trying to start a context in offscreen mode leads to this stacktrace:

[java]24.05.2011 10:38:00 com.jme3.system.lwjgl.LwjglOffscreenBuffer run

INFO: Using LWJGL 2.7.1

24.05.2011 10:38:00 com.jme3.app.Application handleError

SCHWERWIEGEND: Failed to create display

org.lwjgl.LWJGLException: Could not share contexts

at org.lwjgl.opengl.WindowsContextImplementation.nCreate(Native Method)

at org.lwjgl.opengl.WindowsContextImplementation.create(WindowsContextImplementation.java:50)

at org.lwjgl.opengl.Context.<init>(Context.java:131)

at org.lwjgl.opengl.Pbuffer.<init>(Pbuffer.java:225)

at com.jme3.system.lwjgl.LwjglOffscreenBuffer.initInThread(LwjglOffscreenBuffer.java:91)

at com.jme3.system.lwjgl.LwjglOffscreenBuffer.run(LwjglOffscreenBuffer.java:154)

at java.lang.Thread.run(Thread.java:662)[/java]



I also tried to start the second context in headless mode (seems not to invoke apptasks) and display (createContext is displayed in console but the window never shows up).



Is this a bug in the canvas context implementation or is a second context not allowed?

jME3 does not run well with multiple contexts …

However if you’re already using the canvas you should be fine, when the canvas is not visible, you can still render your models

Just use the FrameBuffer class and then read the data via Renderer.readFrameBuffer(), see the TestRenderToMemory example on how to do this.

Thanks for your answer.

You mean, when a context is already started I add a SceneProcessor to it to render my thumbnails? This will not interfere with my model viewer?

I just wanted a clear and independent solution, so I can run both applications (viewer and importer) as standalone, too.

But I understood that I need to share the context when both modules are running in one application, right?

You can create a separate framebuffer and then read from it using readFrameBuffer(). Essentially you need to combine the functionalities in TestRenderToTexture and TestRenderToMemory

For a better architecture I’m going to create two AppStates for the modules and simply activate the importer state when I need to.