Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Cursor mask was uninitialized data, causing problems.
Browse files Browse the repository at this point in the history
Fixes Bugzilla #1461.
  • Loading branch information
icculus committed Jul 21, 2013
1 parent 215b9eb commit f80f765
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/video/windows/SDL_windowsmouse.c
Expand Up @@ -49,11 +49,16 @@ WIN_CreateDefaultCursor()
static SDL_Cursor *
WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
{
/* msdn says cursor mask has to be padded out to word alignment. Not sure
if that means machine word or WORD, but this handles either case. */
const size_t pad = (sizeof (size_t) * 8); /* 32 or 64, or whatever. */
SDL_Cursor *cursor;
HICON hicon;
HDC hdc;
BITMAPV4HEADER bmh;
LPVOID pixels;
LPVOID maskbits;
size_t maskbitslen;
ICONINFO ii;

SDL_zero(bmh);
Expand All @@ -68,14 +73,25 @@ WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
bmh.bV4GreenMask = 0x0000FF00;
bmh.bV4BlueMask = 0x000000FF;

maskbitslen = ((surface->w + (pad - (surface->w % pad))) / 8) * surface->h;
maskbits = SDL_stack_alloc(Uint8,maskbitslen);
if (maskbits == NULL) {
SDL_OutOfMemory();
return NULL;
}

/* AND the cursor against full bits: no change. We already have alpha. */
SDL_memset(maskbits, 0xFF, maskbitslen);

hdc = GetDC(NULL);
SDL_zero(ii);
ii.fIcon = FALSE;
ii.xHotspot = (DWORD)hot_x;
ii.yHotspot = (DWORD)hot_y;
ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
ii.hbmMask = CreateBitmap(surface->w, surface->h, 1, 1, NULL);
ii.hbmMask = CreateBitmap(surface->w, surface->h, 1, 1, maskbits);
ReleaseDC(NULL, hdc);
SDL_stack_free(maskbits);

SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
SDL_assert(surface->pitch == surface->w * 4);
Expand Down

0 comments on commit f80f765

Please sign in to comment.