I’ve been trying non stop for 2 days now and I’m about ready go insane over this problem. I’m trying to load textures on an alternate thread, allowing the main thread to display an animated loader to display progress. I’m aware of the issues this can lead to, but I’ve been reading around a lot (on this forum, mostly) and it sounds like it’s possible.
The problem I’m having, is that no matter what I do, when I call GLContext.makeCurrent() in my loader thread with my shared context, I get one of 2 errors.
Here’s a few things I’ve tried:
GLPbuffer buf = GLDrawableFactory.getFactory().createGLPbuffer( new GLCapabilities(), null, 1, 1, mContext);
mLoaderThread.context = buf.getContext();
mLoaderThread.start();
(mLoaderThread run())
mContext.makeCurrent(); -Error
Exception in thread “Thread-4” javax.media.opengl.GLException: wglShareLists(0x10000, 0x30001) failed: error code 0
at com.sun.opengl.impl.windows.WindowsGLContext.create(WindowsGLContext.java:136)
at com.sun.opengl.impl.windows.WindowsGLContext.makeCurrentImpl(WindowsGLContext.java:150)
at com.sun.opengl.impl.windows.WindowsPbufferGLContext.makeCurrentImpl(WindowsPbufferGLContext.java:102)
at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)
at pixelgame.core.CLoaderThread.run(CLoaderThread.java:55)
GLContext context = canvas.createContext( canvas.getContext() );
mLoaderThread.context = buf.getContext();
mLoaderThread.start();
(mLoaderThread run())
mContext.makeCurrent();-Error
Exception in thread “Thread-4” javax.media.opengl.GLException: Surface already locked
at com.sun.opengl.impl.windows.WindowsOnscreenGLDrawable.lockSurface(WindowsOnscreenGLDrawable.java:157)
at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnscreenGLContext.java:57)
at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)
at pixelgame.core.CLoaderThread.run(CLoaderThread.java:51)
I’ve also tried making my loading thread a GLCanvas object, and giving it an animator the same way my main thread is created. Without Threading.disableSingleThreading(), this would work, but the loader would block the main thread. When I tried using Threading.disableSingleThreading(), it started throwing the first error again. I’ve also tried creating the shared context in my constructor directly after creating the canvas, but this led to the same errors.
Obviously I don’t know how to properly set up a shared GLContext and make it current on a thread. Any ideas what I could be doing wrong?