Variant::stringify(List<void const*, DefaultAllocator>&) const () - Thread issue?

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

Quick note: I am self taught, so my terms and explanation might be a bit wonky.

This issue only occurs once I start instancing over around 124 .tscn.

I haven’t found any articles to suggest that instancing that many .tscn is a problem.

Running Godot 3.2.1 and now 3.2.2 on Fedora 32 (and Windows) getting a hard crash in the editor and a compiled standalone game:

Segmentation fault (core dumped)

via gdb on Fedora 32 I see this when it happens:

Variant::stringify(List<void const*, DefaultAllocator>&) const ()

I think its to do with the way I am using a Thread.

When I remove the Thread the game will not crash.

The Thread is used as I iterate over the quite alot of things that needs to happen outside of the _process loop.

Some of the variables used within the Thread are defined but not altered outside of the Thread. (I would call these globals)

My question is, should I ensure that all variables used within the Thread are also defined ONLY within the Thread and passed function to function.

I have a feeling that even having the variable defined outside of the Thread it still can be shuffled around as needed through memory management which is causing the crash.

Please post code context for better assistance.

Here’s some tips:

  • Memory is shared across threads.
  • Take care in accessing variables and passing references.
  • Use Mutexes to guard access to variables.
  • Recreate (deep copy) data structures.
  • Pass copies of data as userdata to your thread func when calling Thread.start().
  • call_deferred() is thread safe.

If I remember correctly either emit_signal() is thread safe or connect() with the flag CONNECT_DEFERRED is thread safe.

The scene tree is not thread safe. Only modify it from the main thread. You can load scenes in a background thread, but you must safely pass it to the main thread before adding it to the scene tree.

indicainkwell | 2020-06-29 00:17

Thank you for the tips.

I’ve started combing the code in the Thread for any references as you suggest. Naturally I’ve found loads I forgot about!

In the end I’d like to make this thread GDNative C++ so its a good process to go through.

I am assuming that by adding over 124 .tscn instances it is hitting some memory management which is why it starts to crash.

I’d post the code, but its a big chunk and would be out of context, but I think the tips you have given are a good start, I just needed a sanity check on how to make threads safe from a human instead of some slightly abstract docs.

Thanks again!

SoloRobo | 2020-06-29 09:27