[Crash] GDNative modules and threading

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By snk

Hi,

I created a C++ nativescript but it does not appear to be thread-safe. When several threads try to use it the game brutally crashes with a seg fault.

Does someone know how I could make a gdnative module thread-safe ? (without having to launch the threads directly inside the module, I want gdscript threads to use it)

Thanks.

The same happens to me with my Resource class in c++

megazar21 | 2021-07-12 19:58

:bust_in_silhouette: Reply From: megazar21

Yes, it crashed to me also, and with any error.
I think the problem is that multiple threads cannot work with the same GDNative Script, you need to make an instance for each thread.
But you cannot do a duplicate(), also crashes, you need to manually copy de variables for the new instance.

Tell me if that worked!