Hello,
I’m developing my own version of evo-lisa (http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/) in Java, which uses genetic algorithms to find what combination of polygons fits best to an given image.
The biggest issue for now is speed - the main loop of the program is a series of:
render_polygons()
calculate_fitness()
for every individual in the population - every individual has it’s own set of polygons and corresponding fitness.
I’ve made the application use OpenGL (for rendering of the polygons) via jogl and to speed up the application even more I’ve made it to use threads. I’m quite new to jogl, and even to OpenGL in general, and I understand that multi-threading is a VERY-BAD-THING. Even though, I’ve decided to test it - in my case: every thread has a separate render context and threads don’t need to communicate - I’ve thought it reasonable to implement multithreading.
It works splendidly on Linux and the speedup is significant - but while testing the app on Windows I’ve come upon an error.
Exception in thread "Thread-12" javax.media.opengl.GLException: wglShareLists(0x10001, 0x2000c) failed: error code 170
at com.sun.opengl.impl.windows.WindwosGLContext.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 GlWorkerThread.initilizeGL(GlWorkerThread.java:72)
at GlWorkerThread.invokeAtStart(GlWorkerThread.java:90)
at WorkerThread.run(WorkerThread.java:30)
at GlWorkerThread.run(GlWorkerThrad.java:9)
at java.lang.Thread.run(Unknown Source)
the offending line is
public void initializeGL() {
fact = GLDrawableFactory.getFactory();
glCap = new GLCapabilities();
if(fact.canCreateGLPbuffer()) {
myBuff = fact.createGLPbuffer(glCap, null, max_x, max_y, null);
context = myBuff.createContext(null);
context.makeCurrent(); // <---------------------
gl = myBuff.getGL();
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, max_x, max_y, 0, 0, 1);
gl.glMatrixMode(GL.GL_MODELVIEW);
// render all on integer positions
gl.glTranslatef((float)0.375, (float)0.375, (float)0.0);
}
}
This code is run upon GlWorkerThread.start() - once in every thread. The threads are started upon initialization like this:
workerThreads = new GlWorkerThread[options.population_size];
for(int i = 0; i < options.population_size; i++) {
workerThreads[i] = new GlWorkerThread("Thread " + i + " ");
}
(I’ve checked for some obscure concurrency issues by introducing a 500ms delay in this loop, but the result was the same as before)
Am I doing something wrong while initializing OpenGL, or have I found some sort of bug in the windows implementation of jogl? Does somebody have any experience in writing multi-threaded applications for jogl (while reading this forums I’ve seen it is regarded as a sort of taboo)?
I tried a google search for an explanation of error codes returned by the wglShareLists method but found nothing. Can anybody help, please?