Errors when creating ConcavePolygonShape resources in multiple threads

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

I create terrain segments (Mesh and ConcavePolygonShape) in separate worker threads and then assign them to MeshInstance and CollisionShape in scene tree in the main thread. I’m randomly getting these errors and weird problems that look threading-related:

E 0:00:00.571   get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: __null
  <C++ Source>  ./core/rid.h:150 @ get()
E 0:00:00.571   shape_set_data: Condition "!shape" is true.
  <C++ Source>  modules/bullet/bullet_physics_server.cpp:138 @ shape_set_data()

This is what I do in the threads:

var collision_vertices = PoolVector3Array()
collision_vertices.resize(dimensions.x * dimensions.y * 6)

<set up geometry in collision_vectices array>

var shape = ConcavePolygonShape.new()
shape.set_faces(collision_vertices)

The shape is then passed to main thread using call_deferred() and assigned there to CollisionShape existing in scene tree. The errors appear even if I only create the shapes in the threads and don’t use them anywhere.

It looks like this happens only if I use more than one worker thread. Documentation warned about accessing same resources from more than one thread but I don’t see what is causing the problem here.