We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1212

Summary: SDL_compat.c crashes in SDL_SetVideoMode on SDL_SetWindowIcon(SDL_VideoWindow, SDL_VideoIcon);
Product: SDL Reporter: Andrey Budko <e6y>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED WORKSFORME QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86   
OS: Windows (XP)   

Description Andrey Budko 2011-05-24 07:42:21 UTC
This code crashes application:

void I_SetWindowIcon(void)
{
  SDL_Surface *surface;
  Uint8 *mask;
  int i;

  // Generate the mask
  mask = malloc(icon_w * icon_h / 8);
  memset(mask, 0, icon_w * icon_h / 8);

  for (i=0; i<icon_w * icon_h; ++i) 
  {
    if (icon_data[i * 3] != 0x00
     || icon_data[i * 3 + 1] != 0x00
     || icon_data[i * 3 + 2] != 0x00)
    {
      mask[i / 8] |= 1 << (7 - i % 8);
    }
  }

  surface = SDL_CreateRGBSurfaceFrom(icon_data,
    icon_w, icon_h, 24, icon_w * 3,
    0xff << 0, 0xff << 8, 0xff << 16, 0);

  SDL_WM_SetIcon(surface, mask);
  SDL_FreeSurface(surface);
  free(mask);
}

main()
{
  screen = SDL_SetVideoMode(REAL_SCREENWIDTH, REAL_SCREENHEIGHT,
    V_GetNumPixelBits(), init_flags);

  I_SetWindowIcon();

  SDL_FreeSurface(screen);

  screen = NULL;
  screen = SDL_SetVideoMode(REAL_SCREENWIDTH, REAL_SCREENHEIGHT,
    V_GetNumPixelBits(), init_flags);
}

Without I_SetWindowIcon() it works fine.

SDL 1.2.14 works fine here.
Comment 1 Andrey Budko 2011-05-24 07:44:58 UTC
It does not crash if I do not free icon surface

  SDL_WM_SetIcon(surface, mask);
  //SDL_FreeSurface(surface);
Comment 2 Sam Lantinga 2013-05-21 02:41:40 UTC
Hey Ryan, something for you to check with your SDL 1.2 wrapper.
Comment 3 Ryan C. Gordon 2015-02-18 03:29:31 UTC
(In reply to Sam Lantinga from comment #2)
> Hey Ryan, something for you to check with your SDL 1.2 wrapper.

Noted.  :)

--ryan.