我试图在Xubuntu 14.04上制作骨架SDL2应用程序(每个软件包都是最新的)。
这是我的init函数源代码:
int map_x = 50;
int map_y = 20;
//The window we'll be rendering to
SDL_Window *gWindow = NULL;
//The window renderer
SDL_Renderer* gRenderer = NULL;
void
init() {
if (SDL_Init(SDL_INIT_VIDEO) < 0)
eprintf("SDL could not initialize: %s\n", SDL_GetError());
gWindow = SDL_CreateWindow( "SDL Tutorial",\
SDL_WINDOWPOS_UNDEFINED,\
SDL_WINDOWPOS_UNDEFINED,\
map_x, map_y,\
SDL_WINDOW_SHOWN);
if (gWindow == NULL)
eprintf( "window could not be created: %s\n", SDL_GetError());
gRenderer = SDL_CreateRenderer( gWindow, -1,\
SDL_RENDERER_ACCELERATED);
if (gRenderer == NULL)
eprintf("renderer could not be created: %s\n", SDL_GetError());
//Initialize renderer color
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
}
但它在SDL_CreateRenderer函数内部出错。这是gdb输出:
(gdb) run
Starting program: /home/ghi/Desktop/tron/client
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000005885 in ?? ()
(gdb) up
#1 0x00007ffff67dce02 in XCloseIM ()
from /usr/lib/x86_64-linux-gnu/libX11.so.6
(gdb)
#2 0x00007ffff7b8d4fb in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#3 0x00007ffff7b81cce in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#4 0x00007ffff7aed785 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#5 0x00007ffff7aed8c8 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#6 0x0000000000400cc5 in close () at client.c:56
56 SDL_Quit();
(gdb)
#7 0x00007ffff464d723 in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
(gdb)
#8 0x00007ffff4645a46 in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
(gdb)
#9 0x00007ffff4644ea7 in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
(gdb)
#10 0x00007ffff4630e72 in ?? () from /lib/x86_64-linux-gnu/libdbus-1.so.3
(gdb)
#11 0x00007ffff7b8d534 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#12 0x00007ffff7b81cce in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#13 0x00007ffff7aed785 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#14 0x00007ffff7aed8c8 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#15 0x0000000000400cc5 in close () at client.c:56
56 SDL_Quit();
(gdb)
#16 0x00007ffff217ab35 in ?? () from /usr/lib/nvidia-331/libGL.so.1
(gdb)
#17 0x00007ffff0bbda41 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#18 0x00007ffff0ef1814 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#19 0x00007ffff0efd869 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#20 0x00007ffff0db2238 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#21 0x00007ffff0dbd8a7 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#22 0x00007ffff0ba34b3 in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#23 0x00007ffff0b8665c in ?? ()
from /usr/lib/nvidia-331/libnvidia-glcore.so.331.113
(gdb)
#24 0x00007ffff2122b30 in ?? () from /usr/lib/nvidia-331/libGL.so.1
(gdb)
#25 0x00007ffff2122cdc in ?? () from /usr/lib/nvidia-331/libGL.so.1
(gdb)
#26 0x00007ffff2153f59 in ?? () from /usr/lib/nvidia-331/libGL.so.1
(gdb)
#27 0x00007ffff7b8c0ad in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#28 0x00007ffff7b80be6 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#29 0x00007ffff7b80e95 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#30 0x00007ffff7b2ea44 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#31 0x00007ffff7b284c0 in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0
(gdb)
#32 0x0000000000400c38 in init () at client.c:38
38 gRenderer = SDL_CreateRenderer( gWindow, -1,\
(gdb)
#33 0x0000000000400cef in main (argc=1, argv=0x7fffffffdf48) at client.c:61
61 init();
和Makefile:
client : client.o
gcc client.o -Wall -lm -o client `sdl2-config --cflags --libs`
client.o : client.c
gcc -ggdb3 -lm -Wall -c client.c `sdl2-config --cflags --libs`
我在官方存储库中使用libsdl2-dev。有人知道这里有什么问题吗?
可以在此处找到整个来源:https://github.com/hafron/tron/blob/master/client.c
答案 0 :(得分:1)
(之前作为评论发布,结果是一个答案;一些拼写错误)
我对SDL使用一无所知,但是堆栈转储显示你的close()
函数是从nvidia库中调用的。我怀疑你用你的函数取代了其他一些close
标识符。尝试通过在close
前面添加static
关键字,或者将函数重命名为某些static void close() {...}
或其他任何内容来严格本地my_close()