From 7a2831db577cdb91fbbbc2eba22abcafa5883f26 Mon Sep 17 00:00:00 2001 From: jsjtxietian Date: Mon, 11 Dec 2023 19:31:49 +0800 Subject: [PATCH] Prevent crash when call set_text() on a removed treeItem --- scene/gui/tree.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 1d06ce05ae9..8a243fd68f2 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -70,19 +70,27 @@ void TreeItem::Cell::draw_icon(const RID &p_where, const Point2 &p_pos, const Si } void TreeItem::_changed_notify(int p_cell) { - tree->item_changed(p_cell, this); + if (tree) { + tree->item_changed(p_cell, this); + } } void TreeItem::_changed_notify() { - tree->item_changed(-1, this); + if (tree) { + tree->item_changed(-1, this); + } } void TreeItem::_cell_selected(int p_cell) { - tree->item_selected(p_cell, this); + if (tree) { + tree->item_selected(p_cell, this); + } } void TreeItem::_cell_deselected(int p_cell) { - tree->item_deselected(p_cell, this); + if (tree) { + tree->item_deselected(p_cell, this); + } } void TreeItem::_change_tree(Tree *p_tree) {