Cursor mask was uninitialized data, causing problems.
Fixes Bugzilla #1461.
This commit is contained in:
parent
0002acb775
commit
44a6ab168b
1 changed files with 17 additions and 1 deletions
|
@ -49,11 +49,16 @@ WIN_CreateDefaultCursor()
|
||||||
static SDL_Cursor *
|
static SDL_Cursor *
|
||||||
WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
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;
|
SDL_Cursor *cursor;
|
||||||
HICON hicon;
|
HICON hicon;
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
BITMAPV4HEADER bmh;
|
BITMAPV4HEADER bmh;
|
||||||
LPVOID pixels;
|
LPVOID pixels;
|
||||||
|
LPVOID maskbits;
|
||||||
|
size_t maskbitslen;
|
||||||
ICONINFO ii;
|
ICONINFO ii;
|
||||||
|
|
||||||
SDL_zero(bmh);
|
SDL_zero(bmh);
|
||||||
|
@ -68,14 +73,25 @@ WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
||||||
bmh.bV4GreenMask = 0x0000FF00;
|
bmh.bV4GreenMask = 0x0000FF00;
|
||||||
bmh.bV4BlueMask = 0x000000FF;
|
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);
|
hdc = GetDC(NULL);
|
||||||
SDL_zero(ii);
|
SDL_zero(ii);
|
||||||
ii.fIcon = FALSE;
|
ii.fIcon = FALSE;
|
||||||
ii.xHotspot = (DWORD)hot_x;
|
ii.xHotspot = (DWORD)hot_x;
|
||||||
ii.yHotspot = (DWORD)hot_y;
|
ii.yHotspot = (DWORD)hot_y;
|
||||||
ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
|
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);
|
ReleaseDC(NULL, hdc);
|
||||||
|
SDL_stack_free(maskbits);
|
||||||
|
|
||||||
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
|
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
|
||||||
SDL_assert(surface->pitch == surface->w * 4);
|
SDL_assert(surface->pitch == surface->w * 4);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue