Quick question, is GeoMipTerrain::get_elevation threadsafe?

Hi, I am using panda as a collision engine in a server side world simulation.

Right now It only calculates the z position with get_elevation.
I was using get_sz from the root to get the z scale, and found out that this method was not thread safe.
After a few connections (which run on several threads) I received the error:

Assertion failed: (_flags & F_lock_count) != 0 at line 68 of panda/src/pipeline/mutexSimpleImpl.I
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count == 1 at line 49 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 56 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 56 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 56 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 56 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 56 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 56 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 56 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 175 of panda/src/pipeline/reMutexDirect.cxx
Assertion failed: _lock_count > 0 at line 56 of panda/src/pipeline/reMutexDirect.cxx
:thread(error): Deadlock!  All threads blocked.
Segmentation fault (core dumped)

Running on GDB:

#0  0x00007fa370fe7b1e in ThreadSimpleManager::next_context() () from /usr/lib64/panda3d/libpanda.so.1.7
No symbol table info available.
#1  0x00007fa370be9c8a in TransformState::unref() const () from /usr/lib64/panda3d/libpanda.so.1.7
No symbol table info available.
#2  0x00007fa370ac20f9 in ConstPointerTo<TransformState>::~ConstPointerTo() () from /usr/lib64/panda3d/libpanda.so.1.7
No symbol table info available.
#3  0x00007fa370b066fe in NodePath::get_scale() const () from /usr/lib64/panda3d/libpanda.so.1.7
No symbol table info available.
#4  0x0000000000404597 in NodePath::get_sz (this=<value optimized out>, x=<value optimized out>, y=<value optimized out>) at /usr/include/panda3d/nodePath.I:809
No locals.
#5  Terrain::calcZ (this=<value optimized out>, x=<value optimized out>, y=<value optimized out>) at /home/fernando/Documents/project/server/collision.cpp:18

I saved the zScale in a variable and I am using it instead of invoking the method. Still I am wondering, is get_elevation thread safe? Any other functions I should take care? Any panda_thread I could use instead of the default pthread?

Thanks in advance.
[/code]

You are using a version of Panda that is compiled with SIMPLE_THREADS (this is the way that the default version of Panda is compiled). This means that no Panda method is thread safe, unless you use only the Panda interfaces for threading and never use any other threading library (including pthreads or whatever your operating system provides). It also means that your threads created via the Panda interfaces will not be true threads, but will instead be cooperatively shared on a single CPU, so depending on your needs performance may not be what you expect.

If you want to use Panda in conjunction with threaded operations, you should compile it yourself with SIMPLE_THREADS disabled.

I don’t know whether GeoMipTerrain is designed to be thread-safe, though, even if you do this. I suspect it is not, in which case you should probably protect all of your calls to GeoMipTerrain with a mutex, if you are operating on it from different threads.

But let me re-emphasize: you may not use Panda in its default compilation mode in any threaded application, unless you do not use the system threads at all. It will crash and burn horribly.

David