我遇到了一个分段核心转储问题,即使当我打印它时 background->format->bytesperpixel 是 4 并且没有一个指针是 null
SDL_Color GetPixel(SDL_Surface *Background, int x, int y)
{
SDL_Color color;
Uint32 col = 0;
//Determine position
char *pixelPosition = (char *)Background->pixels;
//Offset by Y
pixelPosition += (Background->pitch * y);
//Offset by X
pixelPosition += (Background->format->BytesPerPixel * x);
//Copy pixel data
memcpy(&col, pixelPosition, Background->format->BytesPerPixel);
//Convert to color
SDL_GetRGB(col, Background->format, &color.r, &color.g, &color.b);
return (color);
}