diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index fd007bf7..277fa45d 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -177,6 +177,8 @@ MeterWindow::MeterWindow(const std::wstring& folderPath, const std::wstring& fil */ MeterWindow::~MeterWindow() { + m_State = STATE_CLOSING; + if (!m_OnCloseAction.empty()) { GetRainmeter().ExecuteCommand(m_OnCloseAction.c_str(), this); @@ -383,6 +385,7 @@ void MeterWindow::RemoveWindowExStyle(LONG_PTR flag) */ void MeterWindow::Deactivate() { + if (m_State == STATE_CLOSING) return; m_State = STATE_CLOSING; GetRainmeter().RemoveMeterWindow(this); diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 737bb716..8df9d7c5 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -417,6 +417,7 @@ void Rainmeter::Finalize() DeleteAllUnmanagedMeterWindows(); DeleteAllMeterWindows(); + DeleteAllUnmanagedMeterWindows(); // Redelete unmanaged windows caused by OnCloseAction delete m_TrayWindow; @@ -981,10 +982,13 @@ void Rainmeter::DeleteAllMeterWindows() while (it != m_MeterWindows.cend()) { MeterWindow* mw = (*it).second; - m_MeterWindows.erase(it++); // Remove before deleting MeterWindow + m_MeterWindows.erase(it); // Remove before deleting MeterWindow DialogManage::UpdateSkins(mw, true); delete mw; + + // Get next valid iterator (Fix for iterator invalidation caused by OnCloseAction) + it = m_MeterWindows.cbegin(); } m_MeterWindows.clear();