Deadblock with swapBuffers() and active rendering

A little background:
I decided to use active rendering for an application I’ve been working on. This application has an abstract notion of various types of render surfaces (e.g. fullscreen, window, or a texture). For this, I made the assumption that “buffer swapping” on these surfaces could be done before they were completely released from my rendering thread.

This caused the following situation:

  1. render into an onscreen GLCanvas in my active thread
  2. call swapBuffers on the canvas
  3. that method realizes its not on the AWT thread and tries to execute swapBuffers there
  4. when executing on the AWT thread, it realizes that it isn’t current there and tries to fix that
  5. since the canvas is still current on my thread, that call deadblocks

I got around it by calling Threading.disableSingleThreading(), but I really don’t like relying on this since the documentation is very scary about consequences. How dangerous is disabling single threading now? and are there better ways to handle swapping buffers in active rendering? (the example from Pro Java Game Programming does it this way and doesn’t mention any problems :slight_smile: or should I just assume that it’s unsafe in general to call swapBuffers() while the canvas is still current?

Thanks, and sorry for the long question.

Don’t interact with OpenGL with same context on different threads concurrently, it might work on Windows but will blow on Linux :slight_smile: The only platform that ensures support for threads is Mac OS X (at least from what I’ve read in Apple documentation). And even if something is supported, in reality drivers contains various multithreading bugs, so it’s not wise to use it.

The only safe way seems to render on two different threads with different contexts (and without sharing of data) concurrently (to pbuffer), at least I had no problems with that. Otherwise it’s better to avoid any multi-thread access and render only from thread that is also used for GUI (EDT in case of AWT).