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

Prevent crash when calling set_text() on a removed TreeItem #86028

Conversation

jsjtxietian
Copy link
Contributor

Fixes #85650

Also, should I use add more description or just use ERR_FAIL_NULL is sufficent ?

@jsjtxietian jsjtxietian requested a review from a team as a code owner December 11, 2023 11:34
@AThousandShips
Copy link
Member

AThousandShips commented Dec 11, 2023

This should be before updating the text IMO, in the relevant methods calling these methods

Unless we can confirm it's valid and doesn't have strange sideeffects to update the text off the tree

Also what about other methods like TreeItem::_cell_selected?

Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

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

This would just raise a pointless error. It should be a normal if-check, not an error macro.

Also what about other methods like TreeItem::_cell_selected?

And indeed, other similar methods should also be updated with such checks.

@jsjtxietian
Copy link
Contributor Author

This should be before updating the text IMO, in the relevant methods calling these methods

Yes but there are too many places that might call _changed_notify, since the previous assumption tree items were always in a tree

@jsjtxietian jsjtxietian force-pushed the prevent-crash-when-notify-change-empty-tree branch from 516b67d to 7a2831d Compare December 12, 2023 04:58
@AThousandShips
Copy link
Member

AThousandShips commented Dec 12, 2023

Yes but there are too many places that might call

I don't think that's a valid argument against adding it there, but if you confirm that it's safe and doesn't cause any side effects to manipulate the text etc. not on the tree we can add it just to the places where tree is accessed, otherwise I'd say we shouldn't allow the manipulation if it's not safe

For example, adding a item to the tree does not ensure item_changed is called, so it's not clear if some updates required to happen are done if you manipulate the item off the tree and then add it, we'd need to verify this before we make this change

@jsjtxietian
Copy link
Contributor Author

we'd need to verify this before we make this change

Indeed, you are right. Does anyone familiar with this part of code and can give me some suggestions?

@AThousandShips
Copy link
Member

AThousandShips commented Dec 12, 2023

A basic test would be to try your own code and see if there's any noticeable difference, if there isn't studying the code in more detail should help

Edit: if it doesn't work I'd say each function that doesn't work should have an error fail saying something like "Manipulating TreeItem not in a tree is not supported."

Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

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

I think this is good as is right now. I don't particularly see a reason to check places that call these methods. Changing items should be fine out of Tree.

@AThousandShips
Copy link
Member

I'll trust that the manipulation of these is safe off the tree, despite the aspects mentioned above 🙂, but won't approve myself as I can't confirm it

@akien-mga akien-mga changed the title Prevent crash when call set_text() on a removed treeItem Prevent crash when call set_text() on a removed TreeItem Dec 13, 2023
@akien-mga akien-mga changed the title Prevent crash when call set_text() on a removed TreeItem Prevent crash when calling set_text() on a removed TreeItem Dec 13, 2023
@akien-mga akien-mga merged commit 2d5ceaa into godotengine:master Dec 13, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@jsjtxietian jsjtxietian deleted the prevent-crash-when-notify-change-empty-tree branch December 13, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants