limbonaut / limboai

LimboAI - Behavior Trees and State Machines for Godot 4
MIT License
780 stars 24 forks source link

Crash when freeing agent with performance monitoring enabled #132

Closed jjennings955 closed 3 weeks ago

jjennings955 commented 3 weeks ago

I had an issue when I freed my agent with a BTPlayer with monitor_performance = true, it would crash the game completely with no error message.

I attached a minimal example. If you run main.tscn and click "spawn agent" and then "free agent bad", it should crash immediately with no error message (or it might take a few tries). If you spawn an agent and then click "free agent good" it doesn't crash.

minimal example: godot_crash.zip

This is with the version from the asset store (included) and Godot 4.2.2 (15073afe3)

I also copied some of this logic (below) from the demo code and it still crashed, but I didn't include any of that in this minimal example.

func die() -> void:
    if _is_dead:
        return
    death.emit()
    _is_dead = true
    root.process_mode = Node.PROCESS_MODE_DISABLED
    animation_player.play(&"death")
    collision_shape_2d.set_deferred(&"disabled", true)

    for child in get_children():
        if child is BTPlayer or child is LimboHSM:
            child.set_active(false)

    if get_tree():
        await get_tree().create_timer(10.0).timeout
        print("freeing")
        queue_free()
limbonaut commented 3 weeks ago

Thanks for reporting! I made a PR to fix it. Should come with v1.1.0 release in a few weeks. You can also use this build in the meantime: https://github.com/limbonaut/limboai/actions/runs/9364549957