The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[REPLY]-->[dfrizel] SDL2 does not initialize at all and t
Devesh Sawant
Guest

The initialisation code is this:""
int init(SDL_Renderer * gRenderer, SDL_Window * gWindow)
{
  int success= 1;
  
  if ( SDL_Init(SDL_INIT_VIDEO) < 0   )
  {
    printf(" SDL could not initialise! SDl_Error : %s\n",SDL_GetError());
    success = 0; 
  }
  else
  {
    gWindow = SDL_CreateWindow("NIBBLES>>>0",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,SCREEN_WIDTH,SCREEN_HEIGHT,SDL_WINDOW_SHOWN);
    if ( gWindow == NULL)
    {
      printf("Window could not be created! SDL_Error: %s\n",SDL_GetError());
      success = 0;
    }
    else
    {
      gRenderer  = SDL_CreateRenderer(gWindow,-1,SDL_RENDERER_SOFTWARE);
      if (gRenderer  == NULL )
      {
success = 0;
printf("Renderer could not be created! SDL_Error: %s\n",SDL_GetError());
      }
    }
  }
  return success;
}



""

My OS
""
Linux crunchbang 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2 x86_64 GNU/Linux

""
When SDL tries to run some functions during the execution of the game, the required source file is not found.
These src files:
getenv.c, pthread_key_create.c, pthread_getspecific.c, clock_gettime.c, malloc.c, pthread_mutex_init.c, forward.c, pthread_mutex_lock.c, sigaction.c,
and others also.




Backtrace ( when malloc.c :file not found )
#0  _int_malloc (av=0x7ffff78b5e40, bytes=40) at malloc.c:4317
#1  0x00007ffff75a9012 in __libc_calloc (n=<optimized out>, elem_size=<optimized out>) at malloc.c:4094
#2  0x00007ffff7b9e754 in SDL_CreateMutex_REAL () at /home/devesh/downloads/SDL2-2.0.3/src/thread/pthread/SDL_sysmutex.c:50
#3  0x00007ffff7b0ede5 in SDL_StartEventLoop () at /home/devesh/downloads/SDL2-2.0.3/src/events/SDL_events.c:175
#4  0x00007ffff7ad8825 in SDL_InitSubSystem_REAL (flags=16416) at /home/devesh/downloads/SDL2-2.0.3/src/SDL.c:144
#5  0x0000000000401a01 in init (gRenderer=0x0, gWindow=0x0) at src/nibbles.c:244
#6  0x0000000000401caf in main () at src/nibbles.c:346



At "line 173: if (SDL_VideoInit(NULL) < 0) { "

Backtrace:
#0  SDL_InitSubSystem_REAL (flags=16416) at /home/devesh/downloads/SDL2-2.0.3/src/SDL.c:173
#1  0x0000000000401a01 in init (gRenderer=0x0, gWindow=0x0) at src/nibbles.c:244
#2  0x0000000000401caf in main () at src/nibbles.c:346



I think it's not initialising because none of the files are found .


Then comes --> Cannot find bounds of current function 


Backtrace
#0  0x00007ffff7de1e22 in ?? () from /lib64/ld-linux-x86-64.so.2
#1  0x00007ffff7de4bd6 in ?? () from /lib64/ld-linux-x86-64.so.2
#2  0x00007ffff7dea212 in ?? () from /lib64/ld-linux-x86-64.so.2
#3  0x00007ffff7deabd6 in ?? () from /lib64/ld-linux-x86-64.so.2
#4  0x00007ffff7de92dc in ?? () from /lib64/ld-linux-x86-64.so.2
#5  0x00007ffff7def168 in ?? () from /lib64/ld-linux-x86-64.so.2
#6  0x00007ffff7deabd6 in ?? () from /lib64/ld-linux-x86-64.so.2
#7  0x00007ffff7deeb4a in ?? () from /lib64/ld-linux-x86-64.so.2
#8  0x00007ffff70a9f66 in dlopen_doit (a=<optimized out>) at dlopen.c:67
#9  0x00007ffff7deabd6 in ?? () from /lib64/ld-linux-x86-64.so.2
#10 0x00007ffff70aa2ec in _dlerror_run (operate=0x7ffff70a9f00 <dlopen_doit>, args=0x7fffffffd880) at dlerror.c:164
#11 0x00007ffff70a9ee1 in __dlopen (file=<optimized out>, file@entry=0x7ffff7bae428 "libX11.so.6", mode=<optimized out>, mode@entry=2) at dlopen.c:88
#12 0x00007ffff7b8215b in SDL_LoadObject_REAL (sofile=0x7ffff7bae428 "libX11.so.6") at /home/devesh/downloads/SDL2-2.0.3/src/loadso/dlopen/SDL_sysloadso.c:36
#13 0x00007ffff7b859f1 in SDL_X11_LoadSymbols () at /home/devesh/downloads/SDL2-2.0.3/src/video/x11/SDL_x11dyn.c:175
#14 0x00007ffff7b97c76 in X11_Available () at /home/devesh/downloads/SDL2-2.0.3/src/video/x11/SDL_x11video.c:309
#15 0x00007ffff7b809a1 in SDL_VideoInit_REAL (driver_name=<optimized out>, driver_name@entry=0x0) at /home/devesh/downloads/SDL2-2.0.3/src/video/SDL_video.c:466
#16 0x00007ffff7ad886f in SDL_InitSubSystem_REAL (flags=16416) at /home/devesh/downloads/SDL2-2.0.3/src/SDL.c:173
#17 0x0000000000401a01 in init (gRenderer=0x0, gWindow=0x0) at src/nibbles.c:244
#18 0x0000000000401caf in main () at src/nibbles.c:346



I ran gdb again  and next'd to the point where the segfault signal is received.


'''
 if ( SDL_Init(SDL_INIT_VIDEO) < 0   )
(gdb) 


Program received signal SIGSEGV, Segmentation fault.


0x00007ffff7b227cd in SDL_DestroyRenderer_REAL (renderer=0x7) at /home/devesh/downloads/SDL2-2.0.3/src/render/SDL_render.c:1841
1841    CHECK_RENDERER_MAGIC(renderer, );


(gdb) bt


#0  0x00007ffff7b227cd in SDL_DestroyRenderer_REAL (renderer=0x7) at /home/devesh/downloads/SDL2-2.0.3/src/render/SDL_render.c:1841
#1  0x0000000000401ad8 in close (gRenderer=0x7, gWindow=0x2) at src/nibbles.c:272
#2  0x00007ffff607bdde in xcb_disconnect () from /usr/lib/x86_64-linux-gnu/libxcb.so.1
#3  0x00007ffff62b3027 in XCloseDisplay () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#4  0x00007ffff7b97c9f in X11_Available () at /home/devesh/downloads/SDL2-2.0.3/src/video/x11/SDL_x11video.c:312
#5  0x00007ffff7b809a1 in SDL_VideoInit_REAL (driver_name=<optimized out>, driver_name@entry=0x0) at /home/devesh/downloads/SDL2-2.0.3/src/video/SDL_video.c:466
#6  0x00007ffff7ad886f in SDL_InitSubSystem_REAL (flags=16416) at /home/devesh/downloads/SDL2-2.0.3/src/SDL.c:173
#7  0x0000000000401a01 in init (gRenderer=0x0, gWindow=0x0) at src/nibbles.c:244
#8  0x0000000000401caf in main () at src/nibbles.c:346



'''
Hmmm. 
dfrizel


Joined: 14 Sep 2014
Posts: 7
Location: Vienna / Austria
Smile - Those files are most probably not your problem + you get a lot of debug information.. dlopen, malloc and such things are all basic linux libraries where you just don't have the files. Unless you want to go into linux compiling you'll probably not have contact with those

as for your problem:

#0 Â 0x00007ffff7b227cd in SDL_DestroyRenderer_REAL (renderer=0x7) at /home/devesh/downloads/SDL2-2.0.3/src/render/SDL_render.c:1841
#1 Â 0x0000000000401ad8 in close (gRenderer=0x7, gWindow=0x2) at src/nibbles.c:272

I assume you have a event handler at nibbles.c Line 272?
Check what you do there.


Also this function:
int init(SDL_Renderer * gRenderer, SDL_Window * gWindow)
will not work as you expect it. The create renderer and window within the init will be lost and gRenderer and gWindow will still be 0 outside (or whatever they were before you called init).

What you want to do will require some pointer magic (not a good idea), global variables or a struct and the use of &



br

ps: also please reply via the form. The readability would improve (hopefully) and you can prevent topic duplication.