Fix crash happening on 8 and 16 bit color displays.
Commit f51dbd0669
changed the way of generating
images of ships taking damage, and assumed that the SDL_Surfaces containing the
images were always 24 or 32 bpp. However, SDL will already have converted them
to the display format, so we need to properly handle 8 and 16 bpp as well.
This commit is contained in:
parent
6987eebd3d
commit
a1b3da48c1
|
@ -89,10 +89,33 @@ void loadGameGraphics()
|
|||
continue;
|
||||
shipShape[i] = createSurface(shipShape[i - SHIP_HIT_INDEX]->w, shipShape[i- SHIP_HIT_INDEX]->h);
|
||||
blit(shipShape[i - SHIP_HIT_INDEX], 0, 0, shipShape[i]);
|
||||
|
||||
switch(shipShape[i]->format->BytesPerPixel) {
|
||||
case 4: {
|
||||
uint32_t *p = (uint32_t *)shipShape[i]->pixels;
|
||||
for(int j = 0; j < shipShape[i]->w * shipShape[i]->h; j++)
|
||||
if(p[j])
|
||||
for (int j = 0; j < shipShape[i]->w * shipShape[i]->h; j++)
|
||||
if (p[j])
|
||||
p[j] |= shipShape[i]->format->Rmask;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
uint16_t *p = (uint16_t *)shipShape[i]->pixels;
|
||||
for (int j = 0; j < shipShape[i]->w * shipShape[i]->h; j++)
|
||||
if (p[j])
|
||||
p[j] |= shipShape[i]->format->Rmask;
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: {
|
||||
uint8_t *p = (uint8_t *)shipShape[i]->pixels;
|
||||
for (int j = 0; j < shipShape[i]->w * shipShape[i]->h; j++)
|
||||
if (p[j])
|
||||
p[j] = SDL_MapRGB(shipShape[i]->format, 255, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetColorKey(shipShape[i], (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(shipShape[i]->format, 0, 0, 0));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue