How to avoid deadlock in background loading

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

Godot 3.0.3
Godot documentation gives an example class “” in chapter “Background loading”.
There is a function “_wait_for_resources”:

func _wait_for_resource(res, path):
while true:
	OS.delay_usec(16000) # wait 1 frame
	if queue.size() == 0 || queue[0] != res:
		return pending[path]

that should wait until the resource is loaded by a separate thread “thread_process”.

The code does not work because


will throw an error because VS does not exist. Also an OS.flush does not exist.
When removing this line from code the system crashes, probably a deadlock, because this function will loop forever.

Has anybody had success with this example or does anybody know what “VS.flush()” means ?

cant delete comment, see answer below…

meigel | 2018-08-25 20:06

:bust_in_silhouette: Reply From: volzhs

it was changed to VisualServer.sync()
VS.flush() is used for under Godot 2.x

:bust_in_silhouette: Reply From: meigel

I am trying to do the same in 2.1.5 according to the documentation and VS.flush() is not available. Using VS.sync() does not seem to work either although the method exists. Workaround anyone?