Page 1 of 1

Running irrlicht's beginScene with differen threads?

Posted: Sat Aug 18, 2012 6:03 am
by L o
Hello,

is it possible to run beginScene() with thread 1, and then with another thread, named thread 2? Also, is it possible to do the initial setup, like createDevice(), with a different thread as I run beginScene() with?

Here's a valgrind output:

Code: Select all

 
==11811== Thread 2:
==11811== Invalid read of size 4
==11811==    at 0x41637E6: ??? (in /usr/X11R6/lib/libGL.so.295.71)
==11811==    by 0x81096B9: irr::video::COpenGLDriver::beginScene(bool, bool, irr::video::SColor, irr::video::SExposedVideoData const&, irr::core::rect<int>*) (COpenGLDriver.cpp:840)
==11811==    by 0x8065661: IrrlichtBase::update_graphics() (irrlicht_base.cpp:67)
==11811==    by 0x8064E20: CoreModule::do_work_on_timeout(boost::posix_time::ptime const&) (core_module.h:38)
==11811==    by 0x40993B2: Task::do_exec(ThreadPool*, boost::posix_time::ptime const&, bool) (task.h:92)
==11811==    by 0x409944C: Task::exec(ThreadPool*, boost::posix_time::ptime, bool) (task.h:116)
==11811==    by 0x4099BB4: ThreadPool::do_work(int) (thread_pool.h:462)
==11811==    by 0x4097C88: ThreadBase::run() (thread_worker.cpp:66)
==11811==    by 0x44BFBC7: thread_proxy (in /usr/lib/libboost_thread.so.1.46.1)
==11811==    by 0x4400D5D: clone (in /lib/libc-2.11.3.so)
==11811==  Address 0x27c is not stack'd, malloc'd or (recently) free'd
==11811== 
==11811== 
==11811== Process terminating with default action of signal 11 (SIGSEGV)
==11811==  Access not within mapped region at address 0x27C
==11811==    at 0x41637E6: ??? (in /usr/X11R6/lib/libGL.so.295.71)
==11811==    by 0x81096B9: irr::video::COpenGLDriver::beginScene(bool, bool, irr::video::SColor, irr::video::SExposedVideoData const&, irr::core::rect<int>*) (COpenGLDriver.cpp:840)
==11811==    by 0x8065661: IrrlichtBase::update_graphics() (irrlicht_base.cpp:67)
==11811==    by 0x8064E20: CoreModule::do_work_on_timeout(boost::posix_time::ptime const&) (core_module.h:38)
==11811==    by 0x40993B2: Task::do_exec(ThreadPool*, boost::posix_time::ptime const&, bool) (task.h:92)
==11811==    by 0x409944C: Task::exec(ThreadPool*, boost::posix_time::ptime, bool) (task.h:116)
==11811==    by 0x4099BB4: ThreadPool::do_work(int) (thread_pool.h:462)
==11811==    by 0x4097C88: ThreadBase::run() (thread_worker.cpp:66)
==11811==    by 0x44BFBC7: thread_proxy (in /usr/lib/libboost_thread.so.1.46.1)
==11811==    by 0x4400D5D: clone (in /lib/libc-2.11.3.so)
Thanks for your help.

Greetings,
Johannes

Re: Running irrlicht's beginScene with differen threads?

Posted: Sat Aug 18, 2012 6:53 am
by mongoose7
No. Only one thread can do the rendering. See elsewhere for how you can employ the other CPUs, but this is nontrivial.

Re: Running irrlicht's beginScene with differen threads?

Posted: Sat Aug 18, 2012 7:00 am
by L o
Thanks! I believe you, but only for interest: Why isn't it possible? I have seen such issues with Qt and SDL aswell, but never found out what the reason was...

Re: Running irrlicht's beginScene with differen threads?

Posted: Sat Aug 18, 2012 9:30 am
by hendu
OpenGL is not thread-safe.

Re: Running irrlicht's beginScene with differen threads?

Posted: Thu Aug 30, 2012 11:29 am
by L o
If I use the NULL device on my application's server (which means no OpenGL), is it still then possible to handle beginScene() in different threads? After what has been said, it looks so, but can please someone guarantee?

Re: Running irrlicht's beginScene with differen threads?

Posted: Thu Aug 30, 2012 1:44 pm
by hendu
beginScene with a NULL device does not make any sense...

Re: Running irrlicht's beginScene with differen threads?

Posted: Thu Aug 30, 2012 1:47 pm
by L o
hendu wrote:beginScene with a NULL device does not make any sense...
We are using irrBullet for the server, and thus we thought we needed to use irrlicht, too. However, since it a server, we give irrlicht a null device. Does that make no sense?

Re: Running irrlicht's beginScene with differen threads?

Posted: Thu Aug 30, 2012 2:26 pm
by hendu
Certainly it's going through several unnecessary layers :P

I have no knowledge whether irrbullet depends on beginscene. Signing out of this thread.

Re: Running irrlicht's beginScene with differen threads?

Posted: Thu Aug 30, 2012 4:13 pm
by d3jake
I think for irrBullet, you only need to step the simulation, you shouldn't need to do any beginScene()\endScene() calls, or renderAll(), for that matter. the NULL device means you don't have to or can't do any rendering, so you shouldn't have to do anything render-related.