使用函数 memcpy 的分段核心转储问题

问题描述 投票:0回答:0

我遇到了一个分段核心转储问题,即使当我打印它时 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);
}
c++ segmentation-fault sdl memcpy sdl-1.2
© www.soinside.com 2019 - 2024. All rights reserved.