New mesh in a thread causes a crash

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DrPlamsa
:warning: Old Version Published before Godot 3 was released.

Hello there! I’m making new threads to improve performance and load some terrain in the background. I was testing out threads when I found the following problem:

I have this function in World:

func test_threads():
	var err
	err=mythread.start(newchunk,"test_threads","butt")#Need to pass user data
	var a=mythread.wait_to_finish()

Then this function in

func test_threads(userdata):
	print("chunk.test_threads got run")
	return userdata

And this crashes! Some other cases:
Remove var → it runs fine
Change to var → It crashes
Change to var → It runs fine

So do we know of this problem? Can anyone else make a mesh from a new thread?

:bust_in_silhouette: Reply From: supagu

Modifying a unique resource from multiple threads is not supported, but loading them on threads or handling a reference is perfectly supported. Scenes, textures, meshes, etc. Can be loaded and manipulated on threads, then added to the active scene in the main thread.

What I do to work around this is generate the vertex data I need on a thread, then on the main thread when complete, generate the mesh with the vertex data.
Not ideal, but that is as close as you can get for now.