reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 0c5eb5c04c158376b31824a54e17462db97ae7ea
parent 9f5449c9eb95e75dcd6e57a740ca4329983f79a9
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Fri, 12 Feb 2016 20:24:48 -0800

fix stability issues put into light by the previous commit

9f5449c9eb95e75dcd6e57a740ca4329983f79a9

Diffstat:
Msrc/dialog.cpp | 42+++++++++++++++++-------------------------
Msrc/dialog.hpp | 3+--
2 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -28,15 +28,20 @@ DialogMap Dialog::s_instances; WDL_DLGRET Dialog::Proc(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam) { - Dialog *dlg = nullptr; - - const auto it = Dialog::s_instances.find(handle); - if(it != Dialog::s_instances.end()) - dlg = it->second; + Dialog *dlg; + + if(msg == WM_INITDIALOG) + dlg = reinterpret_cast<Dialog *>(lParam); + else { + const auto it = Dialog::s_instances.find(handle); + if(it == Dialog::s_instances.end()) + return false; + else + dlg = it->second; + } switch(msg) { case WM_INITDIALOG: - dlg = (Dialog *)lParam; dlg->m_handle = handle; // necessary if something in onInit triggers another event @@ -74,16 +79,6 @@ WDL_DLGRET Dialog::Proc(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam) case WM_CONTEXTMENU: dlg->onContextMenu((HWND)wParam, LOWORD(lParam), HIWORD(lParam)); break; - case WM_DESTROY: - // On Windows, WM_DESTROY is emitted in place of WM_INITDIALOG - // if the dialog resource is invalid (eg. because of an unloaded dll). - // - // When this happens, neither lParam nor s_instances will contain - // a pointer to the Dialog instance, so there is nothing we can do. - // At least, let's try to not crash. - if(dlg) - dlg->onDestroy(); - break; }; return false; @@ -98,11 +93,16 @@ Dialog::Dialog(const int templateId) Dialog::~Dialog() { + s_instances.erase(m_handle); + for(Control *control : m_controls | boost::adaptors::map_values) delete control; + const set<int> timers = m_timers; // make an immutable copy + for(const int id : timers) + stopTimer(id); + DestroyWindow(m_handle); - s_instances.erase(m_handle); } INT_PTR Dialog::init(REAPER_PLUGIN_HINSTANCE inst, HWND parent, Modality mode) @@ -254,11 +254,3 @@ void Dialog::onNotify(LPNMHDR info, LPARAM lParam) void Dialog::onContextMenu(HWND, int, int) { } - -void Dialog::onDestroy() -{ - const set<int> timers = m_timers; // make a copy - - for(const int id : timers) - stopTimer(id); -} diff --git a/src/dialog.hpp b/src/dialog.hpp @@ -118,7 +118,6 @@ protected: virtual void onCommand(int); virtual void onNotify(LPNMHDR, LPARAM); virtual void onContextMenu(HWND, int x, int y); - virtual void onDestroy(); private: static WDL_DLGRET Proc(HWND, UINT, WPARAM, LPARAM); @@ -142,7 +141,7 @@ private: class LockDialog { public: LockDialog(Dialog *dlg) - : m_dialog(dlg), m_enabled(dlg->isEnabled()) + : m_dialog(dlg), m_enabled(dlg && dlg->isEnabled()) { if(m_enabled) m_dialog->disable();