From f1f6bea47dbd6acbcebb4782dec7d21b2d691e7e Mon Sep 17 00:00:00 2001 From: dP Date: Sun, 3 Oct 2021 23:00:15 +0300 Subject: [PATCH] Fix #9: Station rating popup crash --- src/citymania/cm_tooltips.cpp | 13 ++++++++++--- src/citymania/cm_watch_gui.cpp | 4 ++-- src/rail_gui.cpp | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/citymania/cm_tooltips.cpp b/src/citymania/cm_tooltips.cpp index bef0539a91..94346f79b4 100644 --- a/src/citymania/cm_tooltips.cpp +++ b/src/citymania/cm_tooltips.cpp @@ -14,6 +14,7 @@ #include "../tile_type.h" #include "../town_map.h" #include "../town.h" +#include "../viewport_func.h" #include "../window_func.h" #include "../zoom_func.h" @@ -485,16 +486,22 @@ public: { /* Always close tooltips when the cursor is not in our window. */ if (!_cursor.in_window) { - delete this; + this->Close(); return; } /* We can show tooltips while dragging tools. These are shown as long as * we are dragging the tool. Normal tooltips work with hover or rmb. */ switch (this->close_cond) { - case TCC_RIGHT_CLICK: if (!_right_button_down) delete this; break; - case TCC_HOVER: if (!_mouse_hovering) delete this; break; + case TCC_RIGHT_CLICK: if (!_right_button_down) this->Close(); break; + case TCC_HOVER: if (!_mouse_hovering) this->Close(); break; case TCC_NONE: break; + + case TCC_EXIT_VIEWPORT: { + Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); + if (w == nullptr || IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y) == nullptr) this->Close(); + break; + } } } }; diff --git a/src/citymania/cm_watch_gui.cpp b/src/citymania/cm_watch_gui.cpp index 50d471eb2a..af82eff691 100644 --- a/src/citymania/cm_watch_gui.cpp +++ b/src/citymania/cm_watch_gui.cpp @@ -520,12 +520,12 @@ void WatchCompany::OnInvalidateData(int data, bool gui_scope) } else if(this->Wtype == EWT_CLIENT){ if (data == 2) { - delete this; + this->Close(); return; } NetworkClientInfo *ci = NetworkClientInfo::GetByClientID((ClientID)this->watched_client); if (!ci) { - delete this; + this->Close(); return; } else { diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 419e400b49..c24f9e0a40 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -527,7 +527,7 @@ struct BuildRailToolbarWindow : Window { { if (!gui_scope) return; - if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) delete this; + if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) this->Close(); } /**