From 14ad5bd238bb3fb2edf8284a1c35f175e2f31d5f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 1 Apr 2013 17:48:23 +0000 Subject: crash fix for AVS git-svn-id: http://svn.miranda-ng.org/main/trunk@4277 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AVS/src/main.cpp | 14 +++++--------- plugins/AVS/src/poll.cpp | 44 +++++++++++++++++++++----------------------- plugins/AVS/src/poll.h | 1 + 3 files changed, 27 insertions(+), 32 deletions(-) (limited to 'plugins/AVS') diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index a357f41c83..53447baaf3 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -1962,8 +1962,6 @@ static int ModulesLoaded(WPARAM wParam, LPARAM lParam) TCHAR szEventName[100]; int result = 0; - InitPolls(); - mir_sntprintf(szEventName, 100, _T("avs_loaderthread_%d"), GetCurrentThreadId()); hLoaderEvent = CreateEvent(NULL, TRUE, FALSE, szEventName); SetThreadPriority( mir_forkthread(PicLoader, 0), THREAD_PRIORITY_IDLE); @@ -1985,7 +1983,7 @@ static int ModulesLoaded(WPARAM wParam, LPARAM lParam) int accCount; ProtoEnumAccounts(&accCount, &accs); - if ( fei != NULL ) { + if (fei != NULL) { LoadDefaultInfo(); PROTOCOLDESCRIPTOR** proto; int protoCount; @@ -2361,6 +2359,7 @@ static int LoadAvatarModule() hMyAvatarChanged = CreateHookableEvent(ME_AV_MYAVATARCHANGED); AllocCacheBlock(); + InitPolls(); HMODULE hDll; if (hDll = GetModuleHandle(_T("gdi32"))) @@ -2368,12 +2367,9 @@ static int LoadAvatarModule() if (AvsAlphaBlend == NULL && (hDll = LoadLibrary(_T("msimg32.dll")))) AvsAlphaBlend = (BOOL (WINAPI *)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION)) GetProcAddress(hDll, "AlphaBlend"); - TCHAR* tmpPath = Utils_ReplaceVarsT(_T("%miranda_userdata%")); - lstrcpyn(g_szDataPath, tmpPath, SIZEOF(g_szDataPath)-1); - mir_free(tmpPath); + lstrcpyn(g_szDataPath, VARST(_T("%miranda_userdata%")), SIZEOF(g_szDataPath)-1); g_szDataPath[MAX_PATH - 1] = 0; _tcslwr(g_szDataPath); - return 0; } @@ -2407,10 +2403,10 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void) { - struct CacheNode *pNode = g_Cache; + UninitPolls(); + struct CacheNode *pNode = g_Cache; while(pNode) { - //DeleteCriticalSection(&pNode->cs); if (pNode->ace.hbmPic != 0) DeleteObject(pNode->ace.hbmPic); pNode = pNode->pNextNode; diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp index dd59cdd46f..340919be0d 100644 --- a/plugins/AVS/src/poll.cpp +++ b/plugins/AVS/src/poll.cpp @@ -64,12 +64,12 @@ int _DebugTrace(HANDLE hContact, const char *fmt, ...); // Functions //////////////////////////////////////////////////////////////////////////// // Items with higher priority at end -static int QueueSortItems( const QueueItem* i1, const QueueItem* i2) +static int QueueSortItems(const QueueItem *p1, const QueueItem *p2) { - return i2->check_time - i1->check_time; + return p2->check_time - p1->check_time; // sort backwards } -static OBJLIST queue( 20, QueueSortItems ); +static OBJLIST queue(20, QueueSortItems); static CRITICAL_SECTION cs; static int waitTime; @@ -82,6 +82,12 @@ void InitPolls() mir_forkthread(RequestThread, NULL); } +void UninitPolls() +{ + DeleteCriticalSection(&cs); + queue.destroy(); +} + // Return true if this protocol can have avatar requested static BOOL PollProtocolCanHaveAvatar(const char *szProto) { @@ -167,24 +173,20 @@ void ProcessAvatarInfo(HANDLE hContact, int type, PROTO_AVATAR_INFORMATIONT *pai if (pai->format == PA_FORMAT_PNG || pai->format == PA_FORMAT_JPEG || pai->format == PA_FORMAT_ICON || pai->format == PA_FORMAT_BMP - || pai->format == PA_FORMAT_GIF) - { + || pai->format == PA_FORMAT_GIF) { // We can load it! MakePathRelative(hContact, pai->filename); ChangeAvatar(hContact, TRUE, TRUE, pai->format); } - else - { + else { // As we can't load it, notify but don't load ChangeAvatar(hContact, FALSE, TRUE, pai->format); } } - else if (type == GAIR_NOAVATAR) - { + else if (type == GAIR_NOAVATAR) { db_unset(hContact, "ContactPhoto", "NeedUpdate"); - if (db_get_b(NULL, AVS_MODULE, "RemoveAvatarWhenContactRemoves", 1)) - { + if (db_get_b(NULL, AVS_MODULE, "RemoveAvatarWhenContactRemoves", 1)) { // Delete settings db_unset(hContact, "ContactPhoto", "RFile"); if (!db_get_b(hContact, "ContactPhoto", "Locked", 0)) @@ -196,15 +198,13 @@ void ProcessAvatarInfo(HANDLE hContact, int type, PROTO_AVATAR_INFORMATIONT *pai ChangeAvatar(hContact, FALSE, TRUE, 0); } } - else if (type == GAIR_FAILED) - { + else if (type == GAIR_FAILED) { int wait = Proto_GetDelayAfterFail(szProto); if (wait > 0) { // Reschedule to request after needed time (and avoid requests before that) - EnterCriticalSection(&cs); + mir_cslock lock(cs); QueueRemove(hContact); QueueAdd(hContact, wait); - LeaveCriticalSection(&cs); } } } @@ -219,7 +219,7 @@ int FetchAvatarFor(HANDLE hContact, char *szProto = NULL) if (szProto != NULL && PollProtocolCanHaveAvatar(szProto) && PollContactCanHaveAvatar(hContact, szProto)) { // Can have avatar, but must request it? if ((g_AvatarHistoryAvail && CallService(MS_AVATARHISTORY_ENABLED, (WPARAM) hContact, 0)) - || (PollCheckProtocol(szProto) && PollCheckContact(hContact, szProto))) + || (PollCheckProtocol(szProto) && PollCheckContact(hContact, szProto))) { // Request it PROTO_AVATAR_INFORMATIONT pai_s = {0}; @@ -272,16 +272,14 @@ static void RequestThread(void *vParam) if (FetchAvatarFor(hContact) == GAIR_WAITFOR) { // Mark to not request this contact avatar for more 30 min - EnterCriticalSection(&cs); - QueueRemove(hContact); - QueueAdd(hContact, REQUEST_WAITFOR_WAIT_TIME); - LeaveCriticalSection(&cs); + { + mir_cslock lock(cs); + QueueRemove(hContact); + QueueAdd(hContact, REQUEST_WAITFOR_WAIT_TIME); + } // Wait a little until requesting again mir_sleep(REQUEST_DELAY); } } - - DeleteCriticalSection(&cs); - queue.destroy(); } diff --git a/plugins/AVS/src/poll.h b/plugins/AVS/src/poll.h index cfc5417488..99d15da999 100644 --- a/plugins/AVS/src/poll.h +++ b/plugins/AVS/src/poll.h @@ -28,6 +28,7 @@ struct QueueItem }; void InitPolls(); +void UninitPolls(); // Add an contact to a queue void QueueAdd(HANDLE hContact); -- cgit v1.2.3