I am having a lot of weird C++ error messages when trying to load a tilemap from another thread, such as 'Condition "!id_map.has(p_rid.get_data())" is true.'
( Observed in Godot 3.5 and v3.5.1.stable.mono.official)
Two questions:
- I am doing anything wrong in the code below?
- the errors seem to come from the physic server. I want to use a tilemap for rendering only; can I dis-activate the physic elements of the tilemap? (Here I am wondering if the high cost of loading a tilemap could be related to loading collision stuff; maybe desactivating this would remove the need to load the tilemap in another thread? )
using Godot;
public class LoadTilemapInThread : Node2D
{
TileMap _tilemap;
public LoadTilemapInThread()
{
// Creating a tilemap and a minimal tileset
_tilemap = new TileMap();
_tilemap.TileSet = new TileSet();
_tilemap.TileSet.CreateTile(1);
_tilemap.TileSet.TileSetTexture(1, (Texture)GD.Load($"res://icon.png"));
// So far, 1) tilemap is not in the tree 2) it contains no tiles
}
public override void _Ready()
{
// setting tiles in another thread
StartLoadingThread();
}
void StartLoadingThread()
{
var thread = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
thread.Start();
}
void Run() // adding tile(s) to the tilemap. Running in another thread.
{
_tilemap.SetCell(0, 0, 1);
this.CallDeferred(nameof(AddTilemapAsChild));
}
// finally adding the tilemap as a child of this.
// Called with CallDeferred to avoid thread-safety issues.
void AddTilemapAsChild()
{
AddChild(_tilemap);
}
static Texture LoadTexture(string name)
=> (Texture)GD.Load($"res://images/{name}");
}
Here are the messages I get:
E 0:00:01.114 get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
<C++ Source> ./core/rid.h:142 @ get()
E 0:00:01.114 body_set_mode: Condition "!body" is true.
<C++ Source> servers/physics_2d/physics_2d_server_sw.cpp:558 @ body_set_mode()
E 0:00:01.114 get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
<C++ Source> ./core/rid.h:142 @ get()
E 0:00:01.114 body_attach_object_instance_id: Condition "!body" is true.
<C++ Source> servers/physics_2d/physics_2d_server_sw.cpp:680 @ body_attach_object_instance_id()
E 0:00:01.114 get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
<C++ Source> ./core/rid.h:142 @ get()
E 0:00:01.114 body_set_collision_layer: Condition "!body" is true.
<C++ Source> servers/physics_2d/physics_2d_server_sw.cpp:708 @ body_set_collision_layer()
E 0:00:01.114 get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
<C++ Source> ./core/rid.h:142 @ get()
E 0:00:01.114 body_set_collision_mask: Condition "!body" is true.
<C++ Source> servers/physics_2d/physics_2d_server_sw.cpp:721 @ body_set_collision_mask()
E 0:00:01.114 get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
<C++ Source> ./core/rid.h:142 @ get()
E 0:00:01.114 body_set_param: Condition "!body" is true.
<C++ Source> servers/physics_2d/physics_2d_server_sw.cpp:734 @ body_set_param()
E 0:00:01.114 get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
<C++ Source> ./core/rid.h:142 @ get()
E 0:00:01.114 body_set_param: Condition "!body" is true.
<C++ Source> servers/physics_2d/physics_2d_server_sw.cpp:734 @ body_set_param()
E 0:00:01.114 get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: nullptr
<C++ Source> ./core/rid.h:142 @ get()
E 0:00:01.114 body_set_state: Condition "!body" is true.
<C++ Source> servers/physics_2d/physics_2d_server_sw.cpp:748 @ body_set_state()