From 447334def7efa0eafe421cf12ad7490b35f775bc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 21 Feb 2022 20:08:19 +0300 Subject: fixes #3025 (occasional crash in AVS) --- plugins/AVS/src/cache.cpp | 1 + plugins/AVS/src/main.cpp | 10 +++++++--- plugins/AVS/src/poll.cpp | 5 +++++ plugins/AVS/src/stdafx.h | 2 +- plugins/AVS/src/version.h | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) (limited to 'plugins/AVS/src') diff --git a/plugins/AVS/src/cache.cpp b/plugins/AVS/src/cache.cpp index 7a38993f06..c60c8cd05b 100644 --- a/plugins/AVS/src/cache.cpp +++ b/plugins/AVS/src/cache.cpp @@ -223,6 +223,7 @@ int SetAvatarAttribute(MCONTACT hContact, uint32_t attrib, int mode) void PicLoader(LPVOID) { Thread_SetName("AVS: PicLoader"); + MThreadLock threadLock(hLoaderThread); uint32_t dwDelay = g_plugin.getDword("picloader_sleeptime", 80); diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index 489a830901..9fd4421229 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -35,7 +35,7 @@ HWND hwndSetMyAvatar = nullptr; HANDLE hMyAvatarsFolder; HANDLE hGlobalAvatarFolder; -HANDLE hLoaderEvent, hShutdownEvent; +HANDLE hLoaderEvent, hLoaderThread, hShutdownEvent; HANDLE hEventChanged, hEventContactAvatarChanged, hMyAvatarChanged; char *g_szMetaName = nullptr; @@ -209,7 +209,6 @@ static int ShutdownProc(WPARAM, LPARAM) g_shutDown = true; SetEvent(hLoaderEvent); SetEvent(hShutdownEvent); - CloseHandle(hShutdownEvent); hShutdownEvent = nullptr; return 0; } @@ -376,6 +375,8 @@ int CMPlugin::Load() int CMPlugin::Unload() { + UnregisterClassW(AVATAR_CONTROL_CLASS, 0); + UninitPolls(); UnloadCache(); @@ -383,7 +384,10 @@ int CMPlugin::Unload() DestroyHookableEvent(hEventContactAvatarChanged); DestroyHookableEvent(hMyAvatarChanged); + if (hLoaderThread) + WaitForSingleObject(hLoaderThread, INFINITE); + CloseHandle(hLoaderEvent); - UnregisterClassW(AVATAR_CONTROL_CLASS, 0); + CloseHandle(hShutdownEvent); return 0; } diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp index 5924800155..ba3d30cf11 100644 --- a/plugins/AVS/src/poll.cpp +++ b/plugins/AVS/src/poll.cpp @@ -41,6 +41,7 @@ ACKRESULT_STATUS. This thread only requests the avatar (and maybe add it to the // Prototypes /////////////////////////////////////////////////////////////////////////// +static HANDLE hRequestThread; static void RequestThread(void *vParam); extern void MakePathRelative(MCONTACT hContact, wchar_t *path); @@ -67,6 +68,9 @@ void InitPolls() void UninitPolls() { + if (hRequestThread) + WaitForSingleObject(hRequestThread, INFINITE); + queue.destroy(); } @@ -206,6 +210,7 @@ int FetchAvatarFor(MCONTACT hContact, char *szProto) static void RequestThread(void *) { Thread_SetName("AVS: RequestThread"); + MThreadLock threadLock(hRequestThread); while (!g_shutDown) { mir_cslockfull lck(cs); diff --git a/plugins/AVS/src/stdafx.h b/plugins/AVS/src/stdafx.h index b49c4aa71d..d5a31465ee 100644 --- a/plugins/AVS/src/stdafx.h +++ b/plugins/AVS/src/stdafx.h @@ -132,7 +132,7 @@ extern HWND hwndSetMyAvatar; extern HANDLE hMyAvatarsFolder; extern HANDLE hGlobalAvatarFolder; -extern HANDLE hLoaderEvent, hShutdownEvent; +extern HANDLE hLoaderEvent, hLoaderThread, hShutdownEvent; extern HANDLE hEventChanged, hEventContactAvatarChanged, hMyAvatarChanged; int GetFileHash(wchar_t* filename); diff --git a/plugins/AVS/src/version.h b/plugins/AVS/src/version.h index 1425892b1c..aef60ef100 100644 --- a/plugins/AVS/src/version.h +++ b/plugins/AVS/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 98 #define __RELEASE_NUM 1 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include -- cgit v1.2.3