From 0936ec15d3c7c036e929fabe924b0da9288c6c8f Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 21 Jul 2013 00:07:43 -0400 Subject: [PATCH] Cursor mask was uninitialized data, causing problems. Fixes Bugzilla #1461. --- src/video/windows/SDL_windowsmouse.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index d61c8b6bb..f50a8724b 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -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); @@ -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);