2014-06-25 114 views
0

探测后,我将其缩小到SDL_DisplayFormat。我在Windows机器上使用msys编译了g++ -o test.exe test.cpp -lmingw32 -lSDLmain -lSDL -lSDL2_image,并运行了可执行文件;然后echo $?返回3 ...为什么SDL_DisplayFormat崩溃?

int main(int argc, char **args) { 
    int status = SDL_Init(SDL_INIT_EVERYTHING); 
    if (status == -1) return 4; 

    screen = SDL_SetVideoMode(W_WIDTH, W_HEIGHT, BPP, SDL_SWSURFACE); 
    if (screen == NULL) return 44; 

    SDL_Surface *loaded_surface = IMG_Load("./res/figure.png"); 
    if (loaded_surface == NULL) return 444; 

    SDL_Surface *background = SDL_DisplayFormat(loaded_surface); 
    return 5; 
    if (background == NULL) return 4444; 

    SDL_FreeSurface(loaded_surface); 

    SDL_BlitSurface(background, NULL, screen, NULL); 

    SDL_Flip(screen); 
    SDL_Delay(2000); 

    return 0; 
} 
+0

它在我的系统上工作正常,当给予'IMG_Load()'的文件存在时。检查文件'。/ res/figure.png'是否存在。 –

+0

是的,它的确如此。可执行文件所在的目录包含一个名为res /的目录,其中存在figure.png ... – user2738698

回答