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

Only recurse depth wise in Tree::_count_selected_items #87943

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

0x0ACB
Copy link
Contributor

@0x0ACB 0x0ACB commented Feb 4, 2024

The current implementation for Tree::_count_selected_items recurses on both depth and width. This very quickly leads to a stackoverflow. I noticed this in the integrated FileDialog which would crash when opening folders with a lot of files.

The new implementation only recurses on depth and iterates on width. Ideally it probably shouldn't recurse at all but I didn't know if std::stack was permitted to use and I guess a Tree shouldn't ever be deep enough to lead to a stack overflow here anyways.

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me, it's only called internally (and only once) and on the root, so no nodes will be missed, using iteration over recursion for this won't change the outcome as the order isn't relevant

On the topic of using a stack or similar there's always benefits and drawbacks to either, and I believe largely trees will be wide and not deep so it's low risk, and we do a lot of other processes here recursively so any changes would best be done in a bigger rework 🙂

@AThousandShips AThousandShips added cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release crash labels Feb 4, 2024
@akien-mga akien-mga merged commit 43a8351 into godotengine:master Feb 5, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 4.2.2.

@akien-mga akien-mga removed the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants