From c45bee74e2fc032ad0e6c7915d56d30f6c4c768d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 3 Mar 2015 22:33:41 +0000 Subject: fix for a memory corruption caused by the global variable in Tipper git-svn-id: http://svn.miranda-ng.org/main/trunk@12310 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TipperYM/src/bitmap_func.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'plugins/TipperYM/src/bitmap_func.cpp') diff --git a/plugins/TipperYM/src/bitmap_func.cpp b/plugins/TipperYM/src/bitmap_func.cpp index e1d20ed86e..d664f7420a 100644 --- a/plugins/TipperYM/src/bitmap_func.cpp +++ b/plugins/TipperYM/src/bitmap_func.cpp @@ -399,12 +399,8 @@ void DestroySkinBitmap() skin.bCached = false; } -void SaveAlpha(LPRECT lpRect) +COLOR32* SaveAlpha(LPRECT lpRect) { - if (skin.colSavedBits) { - mir_free(skin.colSavedBits); - skin.colSavedBits = 0; - } GdiFlush(); if (lpRect->left < 0) lpRect->left = 0; @@ -417,8 +413,8 @@ void SaveAlpha(LPRECT lpRect) int w = lpRect->right - lpRect->left; int h = lpRect->bottom - lpRect->top; - skin.colSavedBits = (COLOR32 *)mir_alloc(sizeof(COLOR32) * w * h); - COLOR32 *p1 = skin.colSavedBits; + COLOR32 *res = (COLOR32 *)mir_alloc(sizeof(COLOR32) * w * h); + COLOR32 *p1 = res; for (int i = 0; i < h; i++) { if (i+y < 0) continue; @@ -430,13 +426,11 @@ void SaveAlpha(LPRECT lpRect) *p1++ = *p2++; } } + return res; } -void RestoreAlpha(LPRECT lpRect, BYTE alpha) +void RestoreAlpha(LPRECT lpRect, COLOR32 *pBits, BYTE alpha) { - if (!skin.colSavedBits) - return; - GdiFlush(); if (lpRect->left < 0) lpRect->left = 0; @@ -449,7 +443,7 @@ void RestoreAlpha(LPRECT lpRect, BYTE alpha) int w = lpRect->right - lpRect->left; int h = lpRect->bottom - lpRect->top; - COLOR32 *p1 = skin.colSavedBits; + COLOR32 *p1 = pBits; for (int i = 0; i < h; i++) { if (i+y < 0) continue; @@ -467,9 +461,6 @@ void RestoreAlpha(LPRECT lpRect, BYTE alpha) ++p1; ++p2; } } - - mir_free(skin.colSavedBits); - skin.colSavedBits = 0; } BOOL IsAlphaTransparent(HBITMAP hBitmap) @@ -504,7 +495,7 @@ BOOL IsAlphaTransparent(HBITMAP hBitmap) void DrawIconExAlpha(HDC hdc, int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, UINT istepIfAniCur, HBRUSH hbrFlickerFreeDraw, UINT diFlags, bool bIsSmiley) { - bool restore = false; + mir_ptr pBits; if (skin.bNeedLayerUpdate && !bIsSmiley) { ICONINFO icon; @@ -512,8 +503,7 @@ void DrawIconExAlpha(HDC hdc, int xLeft, int yTop, HICON hIcon, int cxWidth, int if ( !IsAlphaTransparent(icon.hbmColor)) { RECT rc; SetRect(&rc, xLeft, yTop, xLeft + cxWidth, yTop + cyWidth); - SaveAlpha(&rc); - restore = true; + pBits = SaveAlpha(&rc); } DeleteObject(icon.hbmColor); @@ -523,10 +513,10 @@ void DrawIconExAlpha(HDC hdc, int xLeft, int yTop, HICON hIcon, int cxWidth, int DrawIconEx(hdc, xLeft, yTop, hIcon, cxWidth, cyWidth, istepIfAniCur, hbrFlickerFreeDraw, diFlags); - if (skin.bNeedLayerUpdate && restore) { + if (skin.bNeedLayerUpdate && pBits != NULL) { RECT rc; SetRect(&rc, xLeft, yTop, xLeft + cxWidth, yTop + cyWidth); - RestoreAlpha(&rc); + RestoreAlpha(&rc, pBits); } } @@ -535,9 +525,10 @@ int DrawTextAlpha(HDC hdc, LPCTSTR lpString, int nCount, LPRECT lpRect, UINT uFo RECT rc; SetRect(&rc, lpRect->left - 1, lpRect->top - 1, lpRect->right + 1, lpRect->bottom + 1); - if (skin.bNeedLayerUpdate) SaveAlpha(&rc); + mir_ptr pBits; + if (skin.bNeedLayerUpdate) pBits = SaveAlpha(&rc); int result = DrawText(hdc, lpString, nCount, lpRect, uFormat); - if (skin.bNeedLayerUpdate) RestoreAlpha(&rc); + if (skin.bNeedLayerUpdate) RestoreAlpha(&rc, pBits); return result; } -- cgit v1.2.3