Threading in Panda3D (For loading screens)

Hi everyone,

I’m having a little trouble with creating a loading screen for a game I’m making with Panda3D. Levels in the game take about 10 - 15 seconds to load, and having the program freeze for that long (when using panda without threads to load and attach nodes to the scenegraph) just is rather odd.

I’ve experimented with Windows threads to try and get a quick loading thread up (which i probably did wrongly anyway), however, my program crashes at random intervals usually with the error message:

“Assertion failed: obj->_flag == (PN_int32)DCF_deleted, file c:\temp\mkpr\built\include\deletedChain.T, line 49”

The program does work when my load function was done in the same thread as panda’s main loop though. :\

A. Retardo

Levels should not take 10 - 15 seconds to load you are probably reading an egg convert it to a bam for speed up or use a bam cache so panda bam’s it up for u automatically. Threading on the other hand opens up a whole new bag of warms and random crashes.

On the contrary, some forms of AI (Neural Nets/Precalculated Nodes for Pathfinding), do take relatively long to load. At any rate, it’s not panda elements that cause this pause. Maybe I should place my other panda-unrelated loading code in the thread instead. :stuck_out_tongue:

Still wondering if there is actually a way to load panda elements without crashing randomly though.

there is a threading framework in place and i think there is even a call back interface to update your counter while the model is loading (using model cache some how)

Panda can be made to run multi threaded i just recommend any one against running multi threaded code in genial not panda specific. I just don’t trust most people including myself to do it right.

Awesome, thanks for the info. :stuck_out_tongue: Anywhere I could start if I were to try and get panda to run with threads? (I can’t seem to find any related resources on the forum or the manual)

I’m really just using threads to do loading and rendering at the same time. The nature of the program isn’t really multi-threaded.

Any specific source file to look at?

If you download the Panda source and compile it yourself using the ppremake build interface, you can enable threading within Panda by defining:

#define HAVE_THREADS 1

in your Config.pp file. There is more information in the build documentation.

Once you have build a thread-aware version of Panda, you can load models asynchronously (in a sub-thread) with the loader.loadModel(filename, callback = myCallback) interface. See direct/src/showbase/ for more information on its usage.