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;
}
它在我的系統上工作正常,當給予'IMG_Load()'的文件存在時。檢查文件'。/ res/figure.png'是否存在。 –
是的,它的確如此。可執行文件所在的目錄包含一個名爲res /的目錄,其中存在figure.png ... – user2738698