From bb8db33a66ee6a0080c55790d18bd7630ccc002d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 28 Jul 2012 20:12:16 +0000 Subject: memory corruption fix git-svn-id: http://svn.miranda-ng.org/main/trunk@1231 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Clist_modern/src/modern_cachefuncs.cpp | 94 +++++++++----------------- 1 file changed, 33 insertions(+), 61 deletions(-) (limited to 'plugins/Clist_modern') diff --git a/plugins/Clist_modern/src/modern_cachefuncs.cpp b/plugins/Clist_modern/src/modern_cachefuncs.cpp index 2a14c77224..ce11e9214a 100644 --- a/plugins/Clist_modern/src/modern_cachefuncs.cpp +++ b/plugins/Clist_modern/src/modern_cachefuncs.cpp @@ -834,50 +834,36 @@ void Cache_ProceedAvatarInList(struct ClcData *dat, struct ClcContact *contact) void Cache_GetAvatar(struct ClcData *dat, struct ClcContact *contact) { int old_pos = contact->avatar_pos; - if (g_CluiData.bSTATE != STATE_NORMAL - || (dat->use_avatar_service && !ServiceExists(MS_AV_GETAVATARBITMAP))) // workaround for avatar service and other wich destroys service on OK_TOEXIT - { + // workaround for avatar service and other wich destroys service on OK_TOEXIT + if (g_CluiData.bSTATE != STATE_NORMAL || (dat->use_avatar_service && !ServiceExists(MS_AV_GETAVATARBITMAP))) { contact->avatar_pos = AVATAR_POS_DONT_HAVE; contact->avatar_data = NULL; return; } - if (dat->use_avatar_service && ServiceExists(MS_AV_GETAVATARBITMAP)) - { - if (dat->avatars_show && !db_get_b(contact->hContact, "CList", "HideContactAvatar", 0)) - { + + if (dat->use_avatar_service && ServiceExists(MS_AV_GETAVATARBITMAP)) { + if (dat->avatars_show && !db_get_b(contact->hContact, "CList", "HideContactAvatar", 0)) { contact->avatar_data = (struct avatarCacheEntry *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)contact->hContact, 0); - if (contact->avatar_data == NULL || contact->avatar_data->cbSize != sizeof(struct avatarCacheEntry) - || contact->avatar_data->dwFlags == AVS_BITMAP_EXPIRED) - { + if (contact->avatar_data == NULL || contact->avatar_data->cbSize != sizeof(struct avatarCacheEntry) || contact->avatar_data->dwFlags == AVS_BITMAP_EXPIRED) contact->avatar_data = NULL; - } if (contact->avatar_data != NULL) - { contact->avatar_data->t_lastAccess = (DWORD)time(NULL); - } - } - else - { - contact->avatar_data = NULL; } + else contact->avatar_data = NULL; + Cache_ProceedAvatarInList(dat, contact); } - else - { + else { contact->avatar_pos = AVATAR_POS_DONT_HAVE; - if (dat->avatars_show && !db_get_b(contact->hContact, "CList", "HideContactAvatar", 0)) - { + if (dat->avatars_show && !db_get_b(contact->hContact, "CList", "HideContactAvatar", 0)) { DBVARIANT dbv; - if ( !DBGetContactSettingTString(contact->hContact, "ContactPhoto", "File", &dbv)) - { + if ( !DBGetContactSettingTString(contact->hContact, "ContactPhoto", "File", &dbv)) { HBITMAP hBmp = (HBITMAP) CallService(MS_UTILS_LOADBITMAPT, 0, (LPARAM)dbv.ptszVal); - if (hBmp != NULL) - { + if (hBmp != NULL) { // Make bounds BITMAP bm; - if (GetObject(hBmp,sizeof(BITMAP),&bm)) - { + if (GetObject(hBmp,sizeof(BITMAP),&bm)) { // Create data... HDC hdc; HBITMAP hDrawBmp,oldBmp; @@ -892,77 +878,63 @@ void Cache_GetAvatar(struct ClcData *dat, struct ClcContact *contact) height_clip = dat->avatars_maxheight_size; if (height_clip * bm.bmWidth / bm.bmHeight <= width_clip) - { width_clip = height_clip * bm.bmWidth / bm.bmHeight; - } else - { height_clip = width_clip * bm.bmHeight / bm.bmWidth; - } // Create objs hdc = CreateCompatibleDC(dat->avatar_cache.hdc); hDrawBmp = ske_CreateDIB32(width_clip, height_clip); oldBmp = (HBITMAP)SelectObject(hdc, hDrawBmp); SetBkMode(hdc,TRANSPARENT); - { - POINT org; - GetBrushOrgEx(hdc, &org); - SetStretchBltMode(hdc, HALFTONE); - SetBrushOrgEx(hdc, org.x, org.y, NULL); - } + + POINT org; + GetBrushOrgEx(hdc, &org); + SetStretchBltMode(hdc, HALFTONE); + SetBrushOrgEx(hdc, org.x, org.y, NULL); rc.right = width_clip - 1; rc.bottom = height_clip - 1; // Draw bitmap 8//8 - { - HDC dcMem = CreateCompatibleDC(hdc); - HBITMAP obmp = (HBITMAP)SelectObject(dcMem, hBmp); - StretchBlt(hdc, 0, 0, width_clip, height_clip,dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); - SelectObject(dcMem,obmp); - mod_DeleteDC(dcMem); - } - { - RECT rtr = {0}; - rtr.right = width_clip+1; - rtr.bottom = height_clip+1; - ske_SetRectOpaque(hdc,&rtr); - } + HDC dcMem = CreateCompatibleDC(hdc); + HBITMAP obmp = (HBITMAP)SelectObject(dcMem, hBmp); + StretchBlt(hdc, 0, 0, width_clip, height_clip,dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); + SelectObject(dcMem,obmp); + mod_DeleteDC(dcMem); + + RECT rtr = {0}; + rtr.right = width_clip+1; + rtr.bottom = height_clip+1; + ske_SetRectOpaque(hdc,&rtr); hDrawBmp = (HBITMAP)GetCurrentObject(hdc, OBJ_BITMAP); SelectObject(hdc,oldBmp); mod_DeleteDC(hdc); // Add to list - if (old_pos >= 0) - { + if (old_pos >= 0) { ImageArray_ChangeImage(&dat->avatar_cache, hDrawBmp, old_pos); contact->avatar_pos = old_pos; } - else - { - contact->avatar_pos = ImageArray_AddImage(&dat->avatar_cache, hDrawBmp, -1); - } + else contact->avatar_pos = ImageArray_AddImage(&dat->avatar_cache, hDrawBmp, -1); DeleteObject(hDrawBmp); } // if (GetObject(hBmp,sizeof(BITMAP),&bm)) DeleteObject(hBmp); } //if (hBmp != NULL) + db_free(&dbv); } - db_free(&dbv); } // Remove avatar if needed - if (old_pos >= 0 && contact->avatar_pos == AVATAR_POS_DONT_HAVE) - { + if (old_pos >= 0 && contact->avatar_pos == AVATAR_POS_DONT_HAVE) { ImageArray_RemoveImage(&dat->avatar_cache, old_pos); // Update all items ExecuteOnAllContacts(dat, ReduceAvatarPosition, (void *)&old_pos); } + if (old_pos == AVATAR_POS_ANIMATED && contact->avatar_pos != AVATAR_POS_ANIMATED) - { AniAva_RemoveAvatar( contact->hContact ); - } } } -- cgit v1.2.3