From 467f4b0c5284e4b69200bfa268606487b53e987f Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 19 May 2012 03:02:21 +0000 Subject: [PATCH] Fix crash when changing hotkeys after detaching video ToolTipManager's slots can outlive the windows they're for, so use wxWeakRef to avoid trying to update the tooltip for windows that have been destroyed. Originally committed to SVN as r6830. --- aegisub/src/tooltip_manager.cpp | 30 ++++++++++++++++++++++++++++-- aegisub/src/tooltip_manager.h | 8 +++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/aegisub/src/tooltip_manager.cpp b/aegisub/src/tooltip_manager.cpp index c0ff387a4..7fbdee946 100644 --- a/aegisub/src/tooltip_manager.cpp +++ b/aegisub/src/tooltip_manager.cpp @@ -42,19 +42,43 @@ #include +#ifndef AGI_PRE +#include +#endif + +#include + struct ToolTipBinding { - wxWindow *window; + wxWeakRef window; wxString toolTip; const char *command; const char *context; void Update(); + + ToolTipBinding(wxWindow *window, wxString toolTip, const char *command, const char *context) + : window(window) + , toolTip(toolTip) + , command(command) + , context(context) + { + } + + // clang doesn't like wxWeakRef's copy constructor, so use the assignment + // operator instead + ToolTipBinding(ToolTipBinding const& other) + : toolTip(other.toolTip) + , command(other.command) + , context(other.context) + { + window = other.window; + } }; ToolTipManager::ToolTipManager() { } ToolTipManager::~ToolTipManager() { } void ToolTipManager::Bind(wxWindow *window, wxString tooltip, const char *context, const char *command) { - ToolTipBinding tip = { window, tooltip, command, context }; + ToolTipBinding tip(window, tooltip, command, context); tip.Update(); static ToolTipManager instance; @@ -63,6 +87,8 @@ void ToolTipManager::Bind(wxWindow *window, wxString tooltip, const char *contex } void ToolTipBinding::Update() { + if (!window.get()) return; + std::vector hotkeys = hotkey::get_hotkey_strs(context, command); std::string str; diff --git a/aegisub/src/tooltip_manager.h b/aegisub/src/tooltip_manager.h index c5dcd82da..cd47637fd 100644 --- a/aegisub/src/tooltip_manager.h +++ b/aegisub/src/tooltip_manager.h @@ -36,15 +36,13 @@ #ifndef AGI_PRE #include -#include - -#include -#include -#include #endif struct ToolTipBinding; +class wxString; +class wxWindow; + /// DOCME /// @class ToolTipManager /// @brief DOCME