derkork / godot-statecharts

A state charts extension for Godot 4
MIT License
872 stars 45 forks source link

Game freezes on run when trivial state is used #116

Closed egorzekov closed 6 months ago

egorzekov commented 6 months ago

Hello!

First of all, thanks a lot for the amazing plugin! I am looking forward to using it on my project.

The problem is I can't use it at the moment - the simple state freezes my game when running the scene.

I've also tested it on a new project - have the same issue (video attached). Tested on both 4.2.2 and 4.3dev6 - have the issue on both.

You can't see at the video, but the cursor is actually changed with circle loading cursor while the game is running indicating that some kind of infinite loop is happening in the process.

https://github.com/derkork/godot-statecharts/assets/17830199/ece534b5-ca30-4410-b057-c6c4834367d7

Removing the state - the problem disappears.

https://github.com/derkork/godot-statecharts/assets/17830199/cd8ea72c-d307-444c-81d4-c617d69d393f

I also notice that if I remove 1 transition, breaking the possible loop of the states, the issue also disappears.

https://github.com/derkork/godot-statecharts/assets/17830199/a68f6977-b69f-4a80-948e-f33ec9aeddf0

Screenshot 2024-05-06 at 19 43 39

egorzekov commented 6 months ago

As it usually happens, I figure it out right after reporting the issue 🥲

The problem is that my 2 transitions have empty events set up in the editor, which make them Automatic and causing the infinite loop during transitioning between 2 states.

To handle such stupid mistakes for future users, maybe there's a way to prevent it somehow? E.g.:

  1. Show warnings in the node tree (similar to existing warnings) when Automatic transition looping is detected.
  2. Detect infinite loops in the plugin code and break out of it (e.g. by throwing an error).

Anyway, sorry for bothering you and feel free to close this one.

derkork commented 6 months ago

I have run into this problem occasionally as well but detecting infinite loops at editing time is practically impossible (courtesy to the guards). Adding some kind of counter in the state chart would be an option though so that the state chart will abort if we have a certain number of state changes within the same frame and at least tell you instead of simply freezing up.