[英]SDL 1.2 -> SDL 2.0 (crashing program)
因此,我使用了SDL 2.0遷移指南,最終使代碼編譯時沒有錯誤……但是現在它崩潰了,這是我第一次程序崩潰,並且沒有編譯器可以指導我。 我正在使用LazyFoo的第29個sdl教程,以查看是否可以遷移它。 老實說,我認為我很討厭某個程序,因為我一無所知,所以我把它扔給了你們。 這是我的進度: http : //www.pastebucket.com/21174
您似乎有幾個問題。
首先,您不會在load_images()
函數中加載任何圖像,因此無論何時調用它們,即渲染它們都將是NULL指針。
接下來是您的init()
函數。
bool init()
{
SDL_Init; // <---- REMOVE THIS LINE
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING) == -1 )
{
return false;
}
SDL_Window *sdlWindow; // <----- REMOVE THIS VARIABLE
SDL_Window *window;
SDL_Texture *sdlRenderer; // <----- REMOVE THIS VARIABLE
// Create an application window with the following settings:
// NO NEED FOR SDL_WINDOW_OPENGL replace with SDL_WINDOW_SHOWN
window = SDL_CreateWindow(
"Why is this even alive?", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_SHOWN // flags - see below
);
// sdlWindow should be just window and you should do a NULL check before creating the render
if (window != NULL) {
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
printf("Could not create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
}
}
else {
printf("Could not create window: %s\n", SDL_GetError());
return false;
}
}
現在嘗試一下,看看您的情況如何。 我建議您使用IDE來幫助您,因為這些都是非常簡單的錯誤,通常會立即被發現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.