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

Fix crash when selecting re-added TreeItem::Cell #88917

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

mihe
Copy link
Contributor

@mihe mihe commented Feb 27, 2024

Fixes #88889.

When removing a TreeItem from a Tree it doesn't clear the selected property of the cells in the TreeItem, which means that if you remove this TreeItem from the Tree and then add it back again, and then select the same item/cell, you wouldn't pass this condition:

godot/scene/gui/tree.cpp

Lines 2664 to 2668 in a586e86

if (!selected_cell.selected || allow_reselect) {
selected_cell.selected = true;
selected_item = p_selected;
selected_col = i;

Which then left selected_item at nullptr and would subsequently crash here:

Rect2 rect = get_selected()->get_meta("__focus_rect");

This PR fixes this by simply clearing the selected property of all the item's cells when it's removed from the tree.

@mihe mihe requested a review from a team as a code owner February 27, 2024 15:41
@akien-mga akien-mga added bug crash topic:gui cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Feb 27, 2024
@akien-mga akien-mga added this to the 4.3 milestone Feb 27, 2024
@akien-mga akien-mga merged commit 23191b8 into godotengine:master Feb 27, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@mihe mihe deleted the tree-selection-crash branch February 27, 2024 22:56
@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.

Segfault editting TreeItem immediately after re-adding to Tree.
3 participants