Was gibt denn überhaupt "BytesPerPixel" aus?
Wenn dann noch
m_pBitmap->format->palette != nullptr, dann kann relativ leicht prophezeien, dass der heap verletzt wird. Aus dem Source von SDL_GetRGB():
|
C-/C++-Quelltext
|
1
2
3
4
5
6
|
if ( fmt->palette == NULL ) { ... }
else {
*r = fmt->palette->colors[pixel].r;
*g = fmt->palette->colors[pixel].g;
*b = fmt->palette->colors[pixel].b;
}
|
Du versucht dann evtl. mit einem 4 Byte unsigned int (Uint32) auf eine Palette zuzugreifen, deren Farben nur für einen Bereich bis 255 (8 bpp), bis 65535 (16 bpp) oder bis 16777215 (24 bpp) festgelegt ist. Demach greifst du also auf Speicherbereich zu, der nicht zu
fmt->palette->colors[] gehört. Die folgende ist eine Zugriffsverletzung und ein "Absturz".
Sollte das tatsächlich die Diagnose sein, kannst und solltest du auf die Methode aus der SDL Dokumentation zurückgreifen, die alle Bpp Varianten richtig umwandelt:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
Uint32 getpixel(SDL_Surface *surface, int x, int y)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
return *p;
break;
case 2:
return *(Uint16 *)p;
break;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
break;
case 4:
return *(Uint32 *)p;
break;
default:
return 0; /* shouldn't happen, but avoids warnings */
}
}
|
Quelle: http://sdl.beuc.net/sdl.wiki/Pixel_Access