From 52a840b9c9984bfd4ffd8aaac9f91fc6b015caf1 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 6 Oct 2021 14:32:19 +0800 Subject: [PATCH] Fix crash when tooltip_request_func object is freed --- scene/gui/text_edit.cpp | 6 ++++-- scene/gui/text_edit.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 7dec041197f7..c26311f0fca5 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -6801,6 +6801,7 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const { } String TextEdit::get_tooltip(const Point2 &p_pos) const { + Object *tooltip_obj = ObjectDB::get_instance(tooltip_obj_id); if (!tooltip_obj) { return Control::get_tooltip(p_pos); } @@ -6822,7 +6823,8 @@ String TextEdit::get_tooltip(const Point2 &p_pos) const { } void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata) { - tooltip_obj = p_obj; + ERR_FAIL_NULL(p_obj); + tooltip_obj_id = p_obj->get_instance_id(); tooltip_func = p_function; tooltip_ud = p_udata; } @@ -7368,7 +7370,7 @@ TextEdit::TextEdit() { completion_enabled = false; completion_active = false; completion_line_ofs = 0; - tooltip_obj = nullptr; + tooltip_obj_id = ObjectID(); line_numbers = false; line_numbers_zero_padded = false; line_length_guidelines = false; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 2db4cd5d5ed9..126850f546f5 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -412,7 +412,7 @@ class TextEdit : public Control { VScrollBar *v_scroll; bool updating_scrolls; - Object *tooltip_obj; + ObjectID tooltip_obj_id; StringName tooltip_func; Variant tooltip_ud;