Fixed a issue that Rainmeter crashes at LSLog(). (multithreading issue)

This commit is contained in:
spx 2010-09-19 09:21:25 +00:00
parent df146e4eb4
commit 704558b7df
6 changed files with 29 additions and 7 deletions

View File

@ -148,12 +148,12 @@ void UpdateAboutStatistics(LPCTSTR entryName)
{
int count = ListView_GetItemCount(widget);
std::list<CRainmeter::LOG_INFO>::const_iterator iter = Rainmeter->m_LogData.begin();
std::list<CRainmeter::LOG_INFO>::const_iterator iter = Rainmeter->GetAboutLogData().begin();
LVITEM vitem;
vitem.mask = LVIF_TEXT;
int i = 0;
for ( ; iter != Rainmeter->m_LogData.end(); ++iter)
for ( ; iter != Rainmeter->GetAboutLogData().end(); ++iter)
{
if (i < count)
{

View File

@ -21,6 +21,8 @@
#include "MeterWindow.h"
#define MAXABOUTLOGLINES 20
HWND OpenAboutDialog(HWND hwndOwner, HINSTANCE instance);
void UpdateAboutDialog();
void UpdateAboutStatistics(LPCTSTR entryName = NULL);

View File

@ -548,10 +548,9 @@ BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage)
break;
}
Rainmeter->m_LogData.push_front(logInfo);
if (Rainmeter->m_LogData.size() > MAXABOUTLOGLINES)
if (Rainmeter)
{
Rainmeter->m_LogData.pop_back();
Rainmeter->AddAboutLogInfo(logInfo);
}
// Use the lsapi.dll version of the method if possible

View File

@ -28,7 +28,6 @@
#define LM_GETREVID 9265
#define LM_REGISTERMESSAGE 9263
#define LM_UNREGISTERMESSAGE 9264
#define MAXABOUTLOGLINES 20
#ifdef _DEBUG
#define DEBUGLOG DebugLog

View File

@ -1213,6 +1213,8 @@ CRainmeter::CRainmeter()
m_TrayWindow = NULL;
InitializeCriticalSection(&m_CsLogData);
INITCOMMONCONTROLSEX initCtrls;
initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
initCtrls.dwICC = ICC_TAB_CLASSES;
@ -1254,6 +1256,8 @@ CRainmeter::~CRainmeter()
UpdateDesktopWorkArea(true);
}
DeleteCriticalSection(&m_CsLogData);
GdiplusShutdown(m_GDIplusToken);
}
@ -3731,6 +3735,19 @@ void CRainmeter::DeleteLogFile()
}
}
void CRainmeter::AddAboutLogInfo(const LOG_INFO& logInfo)
{
EnterCriticalSection(&m_CsLogData);
m_LogData.push_front(logInfo);
if (m_LogData.size() > MAXABOUTLOGLINES)
{
m_LogData.pop_back();
}
LeaveCriticalSection(&m_CsLogData);
}
void CRainmeter::SetLogging(bool logging)
{
m_Logging = logging;

View File

@ -195,7 +195,9 @@ public:
void StartLogging();
void StopLogging();
void DeleteLogFile();
std::list<LOG_INFO> m_LogData;
void AddAboutLogInfo(const LOG_INFO& logInfo);
const std::list<LOG_INFO>& GetAboutLogData() { return m_LogData; }
void SetDebug(bool debug);
@ -279,6 +281,9 @@ private:
bool m_Logging;
std::list<LOG_INFO> m_LogData;
CRITICAL_SECTION m_CsLogData;
std::wstring m_ConfigEditor;
std::wstring m_LogViewer;