我使用以下代码调用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: %sn", 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: %sn", SDL_GetError());
return 1;
}
SDL_Quit();
return 0;
}
我没有分割故障。
您能帮我了解问题吗?非常感谢。
好吧,我发现了问题:我不得不重命名intun init()和clsoe(),因为与已经定义的函数发生了冲突。