From 2c6c43c652271bd7cdc667c285ab4fee35beda15 Mon Sep 17 00:00:00 2001 From: Kimmo Pekkola Date: Sat, 17 Oct 2009 06:43:18 +0000 Subject: [PATCH] The window deletion is now delayed when !RainmeterDeactivateConfig is used. This fixes the problem: Issue 116: Crash when skin tries to deactivate self by measure action. --- Library/MeterWindow.cpp | 2 ++ Library/Rainmeter.cpp | 55 +++++++++++++++++++++++++++-------------- Library/Rainmeter.h | 6 ++++- revision-number.h | 2 +- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index f5a370ae..b7e86028 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -2149,6 +2149,8 @@ LRESULT CMeterWindow::OnTimer(WPARAM wParam, LPARAM lParam) // MoveWindow(x, y); // } //} + + Rainmeter->ClearDeleteLaterList(); } else if(wParam == TRANSITIONTIMER) { diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 8e48ead1..2680e18d 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -648,7 +648,7 @@ CRainmeter::~CRainmeter() while (m_Meters.size() > 0) { - DeleteMeterWindow((*m_Meters.begin()).second); // This removes the window from the vector + DeleteMeterWindow((*m_Meters.begin()).second, false); // This removes the window from the vector } if (m_TrayWindow) delete m_TrayWindow; @@ -1203,7 +1203,7 @@ bool CRainmeter::DeactivateConfig(CMeterWindow* meterWindow, int configIndex) // Disable the config in the ini-file WritePrivateProfileString(meterWindow->GetSkinName().c_str(), L"Active", L"0", m_IniFile.c_str()); - return DeleteMeterWindow(meterWindow); + return DeleteMeterWindow(meterWindow, true); } return false; } @@ -1219,30 +1219,47 @@ void CRainmeter::CreateMeterWindow(std::wstring path, std::wstring config, std:: } } -bool CRainmeter::DeleteMeterWindow(CMeterWindow* meterWindow) +void CRainmeter::ClearDeleteLaterList() { - std::map::iterator iter = m_Meters.begin(); - - for (; iter != m_Meters.end(); iter++) + while (!m_DelayDeleteList.empty()) { + DeleteMeterWindow(m_DelayDeleteList.front(), false); + } +} + +bool CRainmeter::DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater) +{ + if (bLater) + { + m_DelayDeleteList.push_back(meterWindow); + } + else + { + m_DelayDeleteList.remove(meterWindow); // Remove the window from the delete later list if it is there + + std::map::iterator iter = m_Meters.begin(); + + for (; iter != m_Meters.end(); iter++) + { + if (meterWindow == NULL) + { + // Delete all meter windows + delete (*iter).second; + } + else if ((*iter).second == meterWindow) + { + delete meterWindow; + m_Meters.erase(iter); + return true; + } + } + if (meterWindow == NULL) { - // Delete all meter windows - delete (*iter).second; - } - else if ((*iter).second == meterWindow) - { - delete meterWindow; - m_Meters.erase(iter); - return true; + m_Meters.clear(); } } - if (meterWindow == NULL) - { - m_Meters.clear(); - } - return false; } diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index a871963b..d95038fd 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -161,13 +161,15 @@ public: std::wstring ParseCommand(const WCHAR* command, CMeterWindow* meterWindow); void ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow); + void ClearDeleteLaterList(); + static PLATFORM IsNT(); static std::wstring ExtractPath(const std::wstring& strFilePath); static void ExpandEnvironmentVariables(std::wstring& strPath); private: void CreateMeterWindow(std::wstring path, std::wstring config, std::wstring iniFile); - bool DeleteMeterWindow(CMeterWindow* meterWindow); + bool DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater); void ScanForConfigs(std::wstring& path); void ScanForThemes(std::wstring& path); void ReadGeneralSettings(std::wstring& path); @@ -219,6 +221,8 @@ private: ULONG_PTR m_GDIplusToken; + std::list m_DelayDeleteList; + static bool c_DummyLitestep; // true, if not a Litestep plugin static std::wstring c_CmdLine; // The command line arguments static GlobalConfig c_GlobalConfig; diff --git a/revision-number.h b/revision-number.h index f6fe32e2..7a5429e2 100644 --- a/revision-number.h +++ b/revision-number.h @@ -1,2 +1,2 @@ #pragma once -const int revision_number = 223; \ No newline at end of file +const int revision_number = 256; \ No newline at end of file