我正试图在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: %sn", 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: %sn", SDL_GetError());
gRenderer = SDL_CreateRenderer( gWindow, -1,
SDL_RENDERER_ACCELERATED);
if (gRenderer == NULL)
eprintf("renderer could not be created: %sn", 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
(之前作为评论发布,结果是一个答案;修复了一些拼写错误)
我对SDL的使用一无所知,但堆栈转储显示您的close()
函数是从英伟达库内部调用的。我怀疑您的函数取代了其他close
标识符。尝试在声明前加一个static
关键字,使close
严格本地化:static void close() {...}
或将函数重命名为某个my_close()
或其他什么。。。