diff --git a/Bitmap.c b/Bitmap.c index d2c9996..cded7e5 100644 --- a/Bitmap.c +++ b/Bitmap.c @@ -36,6 +36,9 @@ void DeleteScreen(Screen *scrn) { if (scrn) { + if (scrn->hOldObj) SelectObject(scrn->hdcBitmap, scrn->hOldObj); + if (scrn->hBitmap) DeleteObject(scrn->hBitmap); + if (scrn->hScreenRgn) DeleteObject((HGDIOBJ) scrn->hScreenRgn); if (scrn->hdcBitmap) DeleteDC(scrn->hdcBitmap); if (scrn->hdcScreen) DeleteDC(scrn->hdcScreen); @@ -57,9 +60,12 @@ PFULLBMPHDR GenerateBitmapInfo(Screen *scrn, BITMAP *bmp) { + // GDI seems to modify the DWORD after the info header, even if we + // don't need a palette (>8 bit BMPs). Thus, an extra RGBQUAD just + // to be safe. PFULLBMPHDR pBmpHdr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - sizeof(struct _FULLBMPHDR)); + sizeof(struct _FULLBMPHDR) + sizeof(RGBQUAD)); RECT rcScrn = {0}; WORD cClrBits = (WORD)(bmp->bmPlanes * bmp->bmBitsPixel); DWORD hdrSize; @@ -337,10 +343,8 @@ cleanup: if (pHdr) HeapFree(GetProcessHeap(), 0, pHdr); - if (scrn->hOldObj) SelectObject(scrn->hdcBitmap, scrn->hOldObj); if (hOldObj) SelectObject(hdcRgn, hOldObj); if (hRgnBitmap) DeleteObject(hRgnBitmap); - if (scrn->hBitmap) DeleteObject(scrn->hBitmap); if (hdcRgn) DeleteDC(hdcRgn);