Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential infinite loop in Colibri::Widget #56

Open
edherbert opened this issue May 8, 2023 · 2 comments
Open

Potential infinite loop in Colibri::Widget #56

edherbert opened this issue May 8, 2023 · 2 comments

Comments

@edherbert
Copy link
Contributor

Hi. As part of my work I've run into what seems to be a potential infinite loop in the Widget::getNextKeyboardNavigableWidget function.

while( nextWidget && !nextWidget->isKeyboardNavigable() )

The problem seems to be that the two widgets register each other as their next widget so the code just loops back and forth between the two. In this scenario, I have a list of buttons representing combat moves. I also create a panel (Colibri::Renderable) to sit ontop of the button to represent cooldown. Seems the panel and the button register themselves as their next widgets. When the button is pressed it disables itself as part of the callback and the panel is set visible to perform the animation.

This loop is fairly rare as I haven't taken the time to dig further into it, but I imagine it relates to how I animate my cover panels. I'm wondering if something can be done to this while loop regardless to prevent it from potentially hanging like this? Perhaps add some extra exit cases?

@darksylinc
Copy link
Owner

Hi!

From what I can see, this would loop infinitely only if widgets create a circular connection, which needs to be done explicitly but should be a valid case.

e.g. if you have:

  • Button 1
  • Button 2
  • Button 3
  • Button 4

If you press "Down" on Button 4 to wrap around to Button 1 but all 4 buttons are disabled, it would loop infinitely.
Note that by default Colibri won't register wrap-around behavior, you need to explicitly tell Colibri that you want Btn 4 to go back to Btn 1 when Down is pressed.

The problem seems to be that the two widgets register each other as their next widget so the code

That won't be a problem because when Btn 1 and Btn 2 register reciprocally, Btn 1 registers Btn 2 for "Down" button, and Btn 2 registers Btn 1 for "Up". The loop checks the next one in the same direction.

@darksylinc
Copy link
Owner

To be clear: I'm not saying this isn't a problem. I'm saying by default I don't see this accidentally triggering.

However there are valid usage cases (like wrap around behavior) that Colibri should support but could trigger the infinite loop you mention if the other conditions are also met (e.g. all buttons are disabled).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants