程序启动时出现SDL_CeateWindow错误

时间:2019-05-16 23:10:43

标签: c sdl assert

下面的代码初始化一个SDL窗口。由于错误,我找不到SDL_CreateWindow()返回NULL

int xwin_init(int w, int h)
{
    int r;
    r = SDL_Init(SDL_INIT_VIDEO);
    assert(win == NULL);
    win = SDL_CreateWindow("PRG Semester Project",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, w, h,SDL_WINDOW_SHOWN);
    SDL_SetWindowTitle(win, "PRG SEM");
    SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(icon_32x32_bits,32, 32, 24, 32*3, 0xff, 0xff00,0xff0000, 0x0000);
    SDL_SetWindowIcon(win, surface);
    SDL_FreeSurface(surface);
    return r;
}

错误消息如下:

prgsem: xwin_sdl.c:58: xwin_init: Assertion win != NULL' failed`

1 个答案:

答案 0 :(得分:0)

虽然我无法告诉您问题所在,但至少值得在初始化视频和创建窗口后检查错误。您可以使用SDL_GetError来执行此操作。通过SDL库可以报告有关通过SDL库报告的错误的消息,您可以根据其他SDL函数(例如您的示例中的SDL_Init)的返回码来告诉何时调用它。