Multithreaded GLFW program renders "static"

jsepia wrote on Sunday, August 09, 2009:

Hi,

I’m making a GLFW game. Yesterday it was single-threaded and everything was being rendered correctly at 60fps. Today I decided to split it into threads, with the main thread running at 15 fps and the rendering thread updating as often as possible (to a fixed maximum of 60 fps).

After a lot of debugging, I managed to get the threads to sync perfectly. But what I see on the screen is this: http://i31.tinypic.com/257hpgn.jpg

I already tried modifying or commenting out some OpenGL/GLFW calls, but they don’t seem to affect the result at all.

Here is some code, namely the renderer thread, the renderer code (called from the thread) and the game loop (which runs on the main thread): http://pastebin.com/m37218c8c

Thanks in advance,

elmindreda wrote on Sunday, August 09, 2009:

GLFW is not involved in actual rendering. Rendering artifacts are between you and OpenGL. OpenGL is a fundamentally single-threaded API and GLFW is mostly thread-unsafe. If you wish to experiment with rendering from a thread other than the main thread, you need to synchronise the threads properly using primitives (mutexes, conditionals, etc). If you wish your code to be portable, confine rendering and window management to the main thread. Tasks not dependent on calling OpenGL may be put into threads other than the main thread.

jsepia wrote on Sunday, August 09, 2009:

Thanks for the reply, I’ll try putting my rendering code in the main thread and looking for OpenGL issues.