From 9a05ea231a41ebb6c53540532b1094057cd9487e Mon Sep 17 00:00:00 2001 From: Rindbee Date: Tue, 4 Oct 2022 10:12:11 +0800 Subject: [PATCH] Make sure to reset the tooltip of its gui_parent when the viewport is removed --- scene/main/viewport.cpp | 12 ++++++++---- scene/main/viewport.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 05b4f181c2e..0795d91035a 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -499,6 +499,13 @@ void Viewport::_notification(int p_what) { // exit event if the change in focus results in the mouse exiting // the window. } break; + + case NOTIFICATION_PREDELETE: { + if (gui_parent) { + gui_parent->gui.tooltip_popup = nullptr; + gui_parent->gui.tooltip_label = nullptr; + } + } break; } } @@ -1155,8 +1162,6 @@ void Viewport::_gui_cancel_tooltip() { } if (gui.tooltip_popup) { gui.tooltip_popup->queue_delete(); - gui.tooltip_popup = nullptr; - gui.tooltip_label = nullptr; } } @@ -1219,8 +1224,6 @@ void Viewport::_gui_show_tooltip() { // Remove previous popup if we change something. if (gui.tooltip_popup) { memdelete(gui.tooltip_popup); - gui.tooltip_popup = nullptr; - gui.tooltip_label = nullptr; } if (!tooltip_owner) { @@ -1252,6 +1255,7 @@ void Viewport::_gui_show_tooltip() { panel->set_flag(Window::FLAG_POPUP, false); panel->set_wrap_controls(true); panel->add_child(base_tooltip); + panel->gui_parent = this; gui.tooltip_popup = panel; diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 471dc412466..6f67649ea37 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -208,6 +208,7 @@ private: friend class ViewportTexture; Viewport *parent = nullptr; + Viewport *gui_parent = nullptr; // Whose gui.tooltip_popup it is. AudioListener2D *audio_listener_2d = nullptr; Camera2D *camera_2d = nullptr;