0
我用下面的代碼調用SDL_QUIT()時遇到分段錯誤:SDL2 SDL_QUIT()分段錯誤
#include <SDL2/SDL.h>
#include <stdio.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int init(){
return SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
}
void close(){
SDL_Quit();
return;
}
int main(int argc, char *argv[])
{
if(init() < 0){
SDL_Log("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(1000);
close();
return 0;
}
這是gdb的輸出:
Breakpoint 1, main (argc=1, argv=0x7fffffffe268) at src/main.c:18
warning: Source file is more recent than executable.
18 if(init() < 0){
(gdb) print $eax
$1 = 4196290
(gdb) step
init() at src/main.c:8
8 return SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
(gdb) print $eax
$2 = 0
(gdb) step
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ??()
(gdb)
然而,當我把一切都放在主像這樣
int main(int argc, char* argv[])
{
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0){
SDL_Log("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_Quit();
return 0;
}
我沒有得到分段錯誤。
你能幫我理解這個問題嗎?非常感謝。
在第一個示例中,您只是初始化視頻。 – aggsol
@aggsol謝謝您的回答;我做了改變,但沒有幫助。 – Itsbananas
段錯在哪裏?調試器說什麼? – Olaf