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.
This commit is contained in:
Thomas Goyne 2012-05-19 03:02:21 +00:00
parent b6e47f1cc0
commit 467f4b0c52
2 changed files with 31 additions and 7 deletions

View file

@ -42,19 +42,43 @@
#include <libaegisub/hotkey.h>
#ifndef AGI_PRE
#include <wx/window.h>
#endif
#include <wx/weakref.h>
struct ToolTipBinding {
wxWindow *window;
wxWeakRef<wxWindow> 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<std::string> hotkeys = hotkey::get_hotkey_strs(context, command);
std::string str;

View file

@ -36,15 +36,13 @@
#ifndef AGI_PRE
#include <list>
#include <vector>
#include <wx/arrstr.h>
#include <wx/string.h>
#include <wx/window.h>
#endif
struct ToolTipBinding;
class wxString;
class wxWindow;
/// DOCME
/// @class ToolTipManager
/// @brief DOCME