GodotNuts / GodotFirebase

Implementations of Firebase for Godot using GDScript
MIT License
554 stars 79 forks source link

[BUG] Crash when connecting to Realtime Database #126

Closed timjrobinson closed 3 years ago

timjrobinson commented 3 years ago

Describe the bug I'm testing out the updates in #124 and Realtime Database is crashing when trying to listen to a path on this line: https://github.com/GodotNuts/GodotFirebase/blob/main/addons/godot-firebase/database/reference.gd#L123 because _auth_obj is null.

Full stack trace:

2021-02-15 17_56_47-Godot Engine - CodeBreaker - SceneSelector tscn

When I put a breakpoint on https://github.com/GodotNuts/GodotFirebase/blob/main/addons/godot-firebase/database/reference.gd#L26 the onready is called after my code. So it seems I need to wait longer for it to be ready before using it? How can I do that?

To Reproduce

Here's some example code that reproduces it:


func _ready():
    Firebase.Auth.connect("signup_succeeded", self, "_create_game")
    Firebase.Auth.connect("login_succeeded", self, "_create_game")
    Firebase.Auth.connect("login_failed", self, "_on_auth_error")
    Firebase.Auth.login_anonymous()

func _create_game(auth_result : Dictionary):
    var rooms_ref : FirebaseDatabaseReference = Firebase.Database.get_database_reference("/games/code-breaker/rooms/", {})

It crashes in _create_game

Expected behavior

I expect this to connect to that path in the database and not crash.

Environment:

timjrobinson commented 3 years ago

I created #127 to demonstrate this. Should be able to just run the examples to see the crash.

fenix-hub commented 3 years ago

Next PR will fix this. Looks like the onready loads references correctly in the ready function, but since it is referencing parent nodes this doesn't work. In Godot child nodes are first loaded, then parents.