Load_threaded_request crashing my game on Android, what am I doing wrong?
Asked Answered
S

5

0

Hi folks, struggling hard with integrating a Loading scene in between the main menu & gameplay scenes of my game. I'm using a singleton (GameState) to hold the path of the nextScreen and then switching to the Loading Scene which loads the next scene (specifically: I am trying to load my Tutorial scene, which contains the Playspace & GameEngine)

var loading_status
var progress : Array[float]
@onready var nextScreen = GameState.nextScreen
func _ready():
ResourceLoader.load_threaded_request(nextScreen)

func _process(delta):
loading_status = ResourceLoader.load_threaded_get_status(nextScreen, progress)
match loading_status:
ResourceLoader.THREAD_LOAD_IN_PROGRESS:
progress_bar.value = progress[0] * 100*2 # Change the ProgressBar value
ResourceLoader.THREAD_LOAD_LOADED:
progress_bar.value = 100
if $Timer.time_left == 0:
get_tree().change_scene_to_packed(ResourceLoader.load_threaded_get(nextScreen))
ResourceLoader.THREAD_LOAD_FAILED:
print("Error. Could not load Resource")

When I run the exported file on Android, the progress bar stays at 0 and then the game crashes. Once, it even forced my phone to restart. The code seems to work on my computer (Mac). But even then, some of the signals & on_ready fxns of the loaded scene do not seem to run? Would really appreciate some help as I am very confused!

Scratches answered 24/10, 2023 at 18:54 Comment(0)
F
0

Scratches For start, prior to initiating the load, check if the resource at given path exists using ResourceLoader::exists()

Freezer answered 24/10, 2023 at 18:59 Comment(0)
S
0

Freezer Hi, I added this check, but no change, still crashing on mobile and ready functions of some children of the scene are not initialized properly

Scratches answered 24/10, 2023 at 22:0 Comment(0)
F
0

Scratches Make a test project that only loads this resource.

Freezer answered 24/10, 2023 at 22:7 Comment(0)
S
0

Like using the resource loader or just load the scene normally? Because if I just load the scene without the resource loader it works fine

Scratches answered 24/10, 2023 at 22:14 Comment(0)
F
0

Scratches Isolate the problem. Load it like you're loading it when it crashes but make a project that does only that. That way you can determine if that's really the cause.

In general, when you have weird bugs, always try to isolate them. Divide and conquer tactics work well when dealing with bugs.

Freezer answered 24/10, 2023 at 22:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.