My marching cubes terrain generator is almost complete, at least the geometry part generating meshes from a static noise definition. I have one last big issue to deal with: I'm running into what appears to be an engine problem that causes a message spam and eventually a crash. This is spammed every frame until it fills the output:
E 0:00:17:0854 remove: Condition "p_elem->_root != this" is true.
<C++ Source> ./core/templates/self_list.h:80 @ remove()
It occurs when too many chunks are added at the same time: Having 64 (4 4 4) chunks in my scene usually works fine and triggers it later, but if I double the view distance or half the chunk size to get 512 (8 8 8) the engine can't handle it for more than a few seconds until it starts.
I was told this might be related to creating and attaching child nodes from a separate thread rather than the main thread. Something I need to do in order to get any decent performance, everything will start to jitter and I get bad lag otherwise. Is there a particular way in which I should add_child() the MeshInstance3D nodes?
An update just as I was typing this: Using call_deferred("add_child", mesh) instead seems to resolve the errors and crashes. I still get glitches with the physics as if the player is lagging and snapping back to their previous position... I read that can be caused by multi-threaded physics, however I have that set to the safe default (disabled) in the project settings.