Skip to content

Conversation

@sapir
Copy link
Contributor

@sapir sapir commented Dec 13, 2020

If a state's "update" stage is None, then the state run loop is infinite, so this fixes it.

@sapir sapir force-pushed the fix-hang-on-no-state-update branch from e05bd97 to 64dca14 Compare December 13, 2020 17:29
@cart
Copy link
Member

cart commented Dec 13, 2020

Ooh very nice catch. I think we can make this a bit simpler by just adding a break in the event that we don't have a "next" and "update" isn't set:

            if let Some(next_stage) = next_stage {
                if next_stage != current_stage {
                    if let Some(exit_current) = self
                        .stages
                        .get_mut(&current_stage)
                        .and_then(|stage| stage.exit.as_mut())
                    {
                        exit_current.run(world, resources);
                    }
                }

                if let Some(enter_next) = self
                    .stages
                    .get_mut(&next_stage)
                    .and_then(|stage| stage.enter.as_mut())
                {
                    enter_next.run(world, resources);
                }
            } else if let Some(update_current) = self
                .stages
                .get_mut(&current_stage)
                .and_then(|stage| stage.update.as_mut())
            {
                update_current.run(world, resources);
                break;
            } else {
                break;
            }

@sapir
Copy link
Contributor Author

sapir commented Dec 13, 2020

I thought this way it would show the flow more clearly: First it loops until it finds the current stage, then it calls "update"

edit: The commit before my force-push (e05bd97) looked more like your version

@cart
Copy link
Member

cart commented Dec 13, 2020

Thats a fair point. At a glance you can tell that "update" only runs once. I'm sold!

@cart cart merged commit 002e22f into bevyengine:master Dec 13, 2020
@sapir sapir deleted the fix-hang-on-no-state-update branch December 13, 2020 20:03
@fopsdev fopsdev mentioned this pull request Jan 24, 2021
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

Successfully merging this pull request may close these issues.

2 participants