ghi
ghi

Reputation: 725

Segmentation fault inside SDL_CreateRenderer

I'm trying to make skeleton SDL2 application on Xubuntu 14.04 (every packages are up to date).

Here is the my init function source code:

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);
}

But it seg faults inside SDL_CreateRenderer function. Here is gdb output:

(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();

And 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`

I'm using libsdl2-dev from official repositories. Do anyone know what is wrong here?

Entire source can be found here: https://github.com/hafron/tron/blob/master/client.c

Upvotes: 0

Views: 1064

Answers (1)

CiaPan
CiaPan

Reputation: 9570

(posted previously as a comment, turned out to be an answer; some typos fixed)

I know nothing about SDL using, but the stack dump shows your close() function was called from inside the nvidia library. I suspect you superseded some other close identifier with your function. Try making your close strictly local by prepending a static keyword to the declaration: static void close() {...} or renaming the function to some my_close() or whatever...

Upvotes: 1

Related Questions