Page 1 of 1

possible? irrlicht loop in a pthread

Posted: Fri Jun 05, 2009 3:13 pm
by axel
I tried to let the main loop of the simple tutorial example run in a pthread,
all pointers that are needed for the loop are passed to the thread, but as soon as the scene is not empty the drawAll() function crashes when the first object should be drawn. The crash happens deep down in the OpenGL code...

Is this a known problem?

Posted: Fri Jun 05, 2009 3:50 pm
by JP
Yup, Irrlicht isn't designed for multithreading. I believe that if you do want to play around with multithreading then the first thing to do is let Irrlicht run in the main thread and spawn extra threads for other tasks.

Posted: Fri Jun 05, 2009 4:18 pm
by axel
Ok - thank you very much!

Is there any way to understand the problem? I mean in my simple play-example no other thread is running (exeption: the main thread, which is waiting for an input)-

I also saw a forum-thread in here
"http://irrlicht.sourceforge.net/phpBB2/ ... ht=pthread"
which might solve the problem, but I actually did not really understand the problem from that.

Posted: Fri Jun 05, 2009 9:36 pm
by hybrid
Actually, the problem here is inherent to OpenGL. You must not call OpenGL calls from a thread different to the one that created the OpenGL context. That's why we promote to use threads for things like I/O or physics.

Posted: Sat Jun 06, 2009 8:14 am
by sio2
hybrid wrote:Actually, the problem here is inherent to OpenGL. You must not call OpenGL calls from a thread different to the one that created the OpenGL context. That's why we promote to use threads for things like I/O or physics.
Same applies to DX9 as well...unless you create the DX device as multithreaded, which can hurt performance (each DX API call takes a critical section).

OpenMP could be useful, but the poster who said they had performance gains hasn't come back with the OpenMP patch for us to try. :( I've used OpenMP before but I don't currently have the time to do it myself (I'm working on a PVS solution).

Posted: Sat Jun 06, 2009 9:36 am
by devsh
although you can add another rendering context and do texture streaming!

Posted: Mon Jun 08, 2009 1:47 pm
by grafikrobot
And if you are willing to do some extra work, and the OpenGL system API you are using allows it, you can switch the OpenGL rendering context from one thread to another. It's what I do for the iPhone port since the iPhone OS has the same single-thread "problem" in that the event system wants to run in the main thread only.