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
SDL2 crash on first steps
ternaryd
Guest

Hi,

The following lines (w/o error handling):

SDL_Init (SDL_INIT_VIDEO);
w = SDL_CreateWindow ("title", x, y, w, h,
SDL_WINDOW_SHOWN);
r = SDL_CreateRenderer (w, -1, 0);

will cause a SIGSEGV in the last line. The
first two calls succeed. I'm running Debian
unstable where I installed the debug version.
So I found out, that this happens in
SDL_x11windows.c on line 347. From that line on
I find:

SDL_DisplayData *displaydata =
(SDL_DisplayData *)
SDL_GetDisplayForWindow(window)->driverdata;

From gdb I know, that "window" is still a valid
pointer, so it seems SDL_GetDisplayForWindow()
must have failed. Under which circumstances is
this possible? I ran the example programs for
SDL_gfx without problems, so the basic
installation on this computer should be OK,
right? Also, this doesn't seem to be a stage
where a correct OpenGL setup is required. This
is basic X11, right?

Is there an alternative start for an SDL
program which would get me around this?

Thanks,

--
Cris
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
HernĂ¡n Gurmendi
Guest

It seems that you are calling the function SDL_CreateWindow with the
variable "w" as the fourth argument which is also the same variable
you are using to store the pointer returned by the mentioned function.

On Mon, Mar 30, 2015 at 5:01 PM, ternaryd wrote:
Quote:
Hi,

The following lines (w/o error handling):

SDL_Init (SDL_INIT_VIDEO);
w = SDL_CreateWindow ("title", x, y, w, h,
SDL_WINDOW_SHOWN);
r = SDL_CreateRenderer (w, -1, 0);

will cause a SIGSEGV in the last line. The
first two calls succeed. I'm running Debian
unstable where I installed the debug version.
So I found out, that this happens in
SDL_x11windows.c on line 347. From that line on
I find:

SDL_DisplayData *displaydata =
(SDL_DisplayData *)
SDL_GetDisplayForWindow(window)->driverdata;

From gdb I know, that "window" is still a valid
pointer, so it seems SDL_GetDisplayForWindow()
must have failed. Under which circumstances is
this possible? I ran the example programs for
SDL_gfx without problems, so the basic
installation on this computer should be OK,
right? Also, this doesn't seem to be a stage
where a correct OpenGL setup is required. This
is basic X11, right?

Is there an alternative start for an SDL
program which would get me around this?

Thanks,

--
Cris
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
Ryan C. Gordon
Guest

Quote:
w = SDL_CreateWindow ("title", x, y, w, h,
SDL_WINDOW_SHOWN);

Is "w" an SDL_Window * (for the return value), or an int (the width of
the window in argument 4)?

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
ternaryd
Guest

On Mon, 30 Mar 2015 20:21:04 -0400
"Ryan C. Gordon" wrote:

Hi Ryan,

Quote:
Is "w" an SDL_Window * (for the return
value), or an int (the width of the window
in argument 4)?

I hoped that this pseudo code would be obvious.
The code is correct. I tried many variants and
rechecked everything many times, and there are
only a few lines. This is a bug in libSDL2,
because even if there is a problem with my
setup, even if I didn't use the correct library
or compile flags, there should be some
indication for what I'm doing wrong. Such a
crash is at least unfriendly.

--
Cris
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
Bob Rubbens
Guest

Can you post the whole program (if it fits in one cpp file) and the command you used to compile it? Op 31 mrt. 2015 07:19 schreef "ternaryd":
Quote:
On Mon, 30 Mar 2015 20:21:04 -0400
"Ryan C. Gordon" wrote:

Hi Ryan,

Quote:
Is "w" an SDL_Window * (for the return
value), or an int (the width of the window
in argument 4)?

I hoped that this pseudo code would be obvious.
The code is correct. I tried many variants and
rechecked everything many times, and there are
only a few lines. This is a bug in libSDL2,
because even if there is a problem with my
setup, even if I didn't use the correct library
or compile flags, there should be some
indication for what I'm doing wrong. Such a
crash is at least unfriendly.

--
Cris
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
ternaryd
Guest

On Tue, 31 Mar 2015 11:00:07 +0200
Bob Rubbens wrote:

Quote:
Can you post the whole program (if it fits in
one cpp file) and the command you used to
compile it?

Sure, well, a c file (don't like c++). It's
from
http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php
slightly edited. While trying to make it work,
I made many versions and read documentation and
source of many things, but this is the first
version, besides the one which is at the link
above. Note also, that most of the code is never
executed, as it will crash at the line creating
the renderer.

I even added the line
SDL_Init (SDL_INIT_EVERYTHING)
at the beginning of function init(), but it
would crash immediately there, the following
code becoming irrelevant.

#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

SDL_Window *gWindow = NULL;
SDL_Renderer *gRenderer = NULL;
SDL_Texture *gTexture = NULL;

bool init (void);
bool loadMedia (void);
void close (void);
SDL_Texture *loadTexture (char *path);

bool
init (void)
{
if (SDL_VideoInit (NULL) < 0)
{
printf ("SDL could not initialize! SDL
Error: %s\n", SDL_GetError ());
return false;
}

gWindow = SDL_CreateWindow ("SDL-Tut",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (!gWindow)
{
printf ("Window could not be created! SDL
Error: %s\n", SDL_GetError ());
return false;
}

gRenderer = SDL_CreateRenderer (gWindow, -1,
0);
if (gRenderer == NULL)
{
printf ("Renderer could not be created! SDL
Error: %s\n", SDL_GetError ());
return false;
}

SDL_SetRenderDrawColor (gRenderer, 255, 255,
255, 255);
SDL_RenderClear (gRenderer);

if ((IMG_Init (IMG_INIT_PNG) & IMG_INIT_PNG)
== 0)
{
printf ("SDL_image could not initialize!
SDL_image Error: %s\n", IMG_GetError ());
return false;
}

return true;
}

bool
loadMedia (void)
{
bool success = true;

gTexture = loadTexture ("texture.png");
if (gTexture == NULL)
{
printf ("Failed to load texture image!\n");
success = false;
}

return success;
}

void
close (void)
{
SDL_DestroyTexture (gTexture);
gTexture = NULL;

SDL_DestroyRenderer (gRenderer);
SDL_DestroyWindow (gWindow);
gWindow = NULL;
gRenderer = NULL;

IMG_Quit ();
SDL_Quit ();
}

SDL_Texture *
loadTexture (char *path)
{
SDL_Texture *newTexture = NULL;
SDL_Surface *loadedSurface;

loadedSurface = IMG_Load (path);
if (loadedSurface == NULL)
{
printf ("Unable to load image %s! SDL_image
Error: %s\n", path, IMG_GetError ());
}
else
{
newTexture = SDL_CreateTextureFromSurface
(gRenderer, loadedSurface);
if (newTexture == NULL)
{
printf ("Unable to create texture from
%s! SDL Error: %s\n", path, SDL_GetError ());
}

SDL_FreeSurface (loadedSurface);
}

return newTexture;
}

int
main (int argc, char **args)
{
if (!init ())
printf ("Failed to initialize!\n");
else
{
if (!loadMedia ())
printf ("Failed to load media!\n");
else
{
bool quit = false;
SDL_Event e;

while (!quit)
{
while (SDL_PollEvent (&e) != 0)
if (e.type == SDL_QUIT)
quit = true;

SDL_RenderClear (gRenderer);
SDL_RenderCopy (gRenderer, gTexture,
NULL, NULL);
SDL_RenderPresent (gRenderer);
}
}
}

close();

return 0;
}

My Makefile produces the following two lines
(including some other libs for some other
purpose, but they don't change anything):

gcc -g3 -ggdb -Wall -Werror -o txr3.o -c txr3.c
gcc -g3 -ggdb -Wall -Werror -o txr3 txr3.o
-lSDL2_gfx -lSDL2_image -lSDL2_ttf -lSDL2
-lpthread -lm

--
Cris
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
Daniel Gibson
Guest

If SDL_Init() already crashes you're in real trouble.
The reason for that crash should be debugged, your other code doesn't
even matter (as it's not expected to work without SDL_Init())

On 03/31/2015 06:58 PM, ternaryd wrote:
Quote:
On Tue, 31 Mar 2015 11:00:07 +0200
Bob Rubbens wrote:

Quote:
Can you post the whole program (if it fits in
one cpp file) and the command you used to
compile it?

Sure, well, a c file (don't like c++). It's
from
http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php
slightly edited. While trying to make it work,
I made many versions and read documentation and
source of many things, but this is the first
version, besides the one which is at the link
above. Note also, that most of the code is never
executed, as it will crash at the line creating
the renderer.

I even added the line
SDL_Init (SDL_INIT_EVERYTHING)
at the beginning of function init(), but it
would crash immediately there, the following
code becoming irrelevant.

#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

SDL_Window *gWindow = NULL;
SDL_Renderer *gRenderer = NULL;
SDL_Texture *gTexture = NULL;

bool init (void);
bool loadMedia (void);
void close (void);
SDL_Texture *loadTexture (char *path);

bool
init (void)
{
if (SDL_VideoInit (NULL) < 0)
{
printf ("SDL could not initialize! SDL
Error: %s\n", SDL_GetError ());
return false;
}

gWindow = SDL_CreateWindow ("SDL-Tut",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (!gWindow)
{
printf ("Window could not be created! SDL
Error: %s\n", SDL_GetError ());
return false;
}

gRenderer = SDL_CreateRenderer (gWindow, -1,
0);
if (gRenderer == NULL)
{
printf ("Renderer could not be created! SDL
Error: %s\n", SDL_GetError ());
return false;
}

SDL_SetRenderDrawColor (gRenderer, 255, 255,
255, 255);
SDL_RenderClear (gRenderer);

if ((IMG_Init (IMG_INIT_PNG) & IMG_INIT_PNG)
== 0)
{
printf ("SDL_image could not initialize!
SDL_image Error: %s\n", IMG_GetError ());
return false;
}

return true;
}

bool
loadMedia (void)
{
bool success = true;

gTexture = loadTexture ("texture.png");
if (gTexture == NULL)
{
printf ("Failed to load texture image!\n");
success = false;
}

return success;
}

void
close (void)
{
SDL_DestroyTexture (gTexture);
gTexture = NULL;

SDL_DestroyRenderer (gRenderer);
SDL_DestroyWindow (gWindow);
gWindow = NULL;
gRenderer = NULL;

IMG_Quit ();
SDL_Quit ();
}

SDL_Texture *
loadTexture (char *path)
{
SDL_Texture *newTexture = NULL;
SDL_Surface *loadedSurface;

loadedSurface = IMG_Load (path);
if (loadedSurface == NULL)
{
printf ("Unable to load image %s! SDL_image
Error: %s\n", path, IMG_GetError ());
}
else
{
newTexture = SDL_CreateTextureFromSurface
(gRenderer, loadedSurface);
if (newTexture == NULL)
{
printf ("Unable to create texture from
%s! SDL Error: %s\n", path, SDL_GetError ());
}

SDL_FreeSurface (loadedSurface);
}

return newTexture;
}

int
main (int argc, char **args)
{
if (!init ())
printf ("Failed to initialize!\n");
else
{
if (!loadMedia ())
printf ("Failed to load media!\n");
else
{
bool quit = false;
SDL_Event e;

while (!quit)
{
while (SDL_PollEvent (&e) != 0)
if (e.type == SDL_QUIT)
quit = true;

SDL_RenderClear (gRenderer);
SDL_RenderCopy (gRenderer, gTexture,
NULL, NULL);
SDL_RenderPresent (gRenderer);
}
}
}

close();

return 0;
}

My Makefile produces the following two lines
(including some other libs for some other
purpose, but they don't change anything):

gcc -g3 -ggdb -Wall -Werror -o txr3.o -c txr3.c
gcc -g3 -ggdb -Wall -Werror -o txr3 txr3.o
-lSDL2_gfx -lSDL2_image -lSDL2_ttf -lSDL2
-lpthread -lm


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
ternaryd
Guest

On Tue, 31 Mar 2015 11:00:07 +0200
Bob Rubbens wrote:

Quote:
Can you post the whole program (if it fits in
one cpp file) and the command you used to
compile it?

I apologize for the noise; just found the
mistake. The tutorial program was meant for a
C++ compiler where this seems to be legal, and
I used it as a C program, where it is not: The
author uses "close" as a function name, which
of course clashes with the libc function to
close a file descriptor. And I didn't pay
attention. It certainly did puzzle me.

Sorry,

--
Cris
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
Daniel Gibson
Guest

On 03/31/2015 07:19 PM, ternaryd wrote:
Quote:

I apologize for the noise; just found the
mistake. The tutorial program was meant for a
C++ compiler where this seems to be legal, and
I used it as a C program, where it is not: The
author uses "close" as a function name, which
of course clashes with the libc function to
close a file descriptor. And I didn't pay
attention. It certainly did puzzle me.

Very Happy

I also ran into that trap before (with shutdown()).
Since then I try to follow the rule to make as many functions as
possible static and prefix the other ones with something to (hopefully)
make them unique.

Cheers,
Daniel
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 crash on first steps
Ryan C. Gordon
Guest

Quote:
Quote:
Is "w" an SDL_Window * (for the return
value), or an int (the width of the window
in argument 4)?

I hoped that this pseudo code would be obvious.

Sorry, we try to narrow down bugs based on information we have available
to us, and similar mistakes have been seen on the mailing list before.

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org