Level loading with threads runs sometimes and doesn't run sometimes.

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

I am trying to load a scene in the background while displaying a loading screen till the scene loads and then changing the scene to the loaded scene and I am using threads and ResourceLoader to do so. On my computer it runs sometimes and doesn’t run other times. And, on android it never gets completed the loading screen comes up and then the game just hangs.

On pressing the play button:

func _on_play_pressed():
		go_to_scene(level_to_load, true)

The go_to_scene():

func go_to_scene(new_scene, loading):
	if (loading):
		loading_thread = Thread.new()
		loading_thread.start(self, 'prep_scene', ResourceLoader.load_interactive(new_scene), 2)

The prep_scene():

func prep_scene(interactive_ldr):
	while (true):
		var err = interactive_ldr.poll();
		if(err == ERR_FILE_EOF):
			return interactive_ldr.get_resource();

The _on_load_level_done():

func _on_load_level_done():
	var interactive_ldr = loading_thread.wait_to_finish()
	print('thread', loading_thread.is_active())
	if get_tree().change_scene_to(interactive_ldr) != OK:

I’m also having a similar issue with swapping texture resources for an inventory slot sprite.

LunaticWyrm467 | 2022-04-26 23:14