Charpurrr / SuperMarioSolarEngine

An open source fanmade 2D Mario engine that implements elements from all the mainline 3D titles
https://docs.google.com/document/d/1hzFKpgm-1IukFWBig9A5ZsCQQEqVqJFVrNOAVmHSHJI/edit
MIT License
14 stars 7 forks source link

Cannot call method 'get_tree' on a previously freed instance #21

Closed Charpurrr closed 5 months ago

Charpurrr commented 5 months ago

Description: SFXLayer tries to add its sound effect player to the scene while it's being reloaded

To recreate: Run a scene with Mario and UI funny_slope_test.tscn, spam the reset button and X button (spin attack) repeatedly until you receive the error.

The Error: Cannot call method 'get_tree' on a previously freed instance. The code it points to: res://util/sfx_layer.gd

func play_sfx_at(node: Node):
    var timer: SceneTreeTimer = node.get_tree().create_timer(delay_time)

    await timer.timeout

    var player := AudioStreamPlayer.new()
    new_pick = sfx_list.pick_random()

    if force_new and sfx_list.size() > 1:
        while new_pick == last_pick:
            new_pick = sfx_list.pick_random()

    if overwrite_other:
        node.get_tree().call_group(bus, &"queue_free") < HERE

Cause of error: Playing a sound effect on the same frame that the scene is being reloaded.

Charpurrr commented 5 months ago

Fixed in 106c9fd8c3883016f6e1ff66134be3bf3696d848