Immediate core dump

I setup a program that does nothing but initialize then screen, but yet
it core dumped. I added a putpixel function I wrote followed by an
SDL_WaitEvent. It will put the pixel to the screen, but after I cause an

event it still core dumps. (by the way is the mouse moving an event?,
the program dump core if I move the mouse)
I have SDL_Quit at the end and with an atexit statement but that isn’t
helping. This is becoming a problem because I wrote functions to draw
some graphics primitives, but sometimes for no apparent reason things
don’t get drawn, for example my rectangle drawing statement which is
simply four calls to a line drawing function, draws the top and left
side, but not the right and bottom sides. My code seems to be right, but

it might not be. With SDL being so unstable I don’t know whose at fault.

Also my PutPixel routine has a simple clipping check that just returns
without drawing anything if X or Y is out of bounds, yet if I try to
draw a line or rectangle or something that is out of bounds, none of it
gets drawn at all. This confuses me because I would think either the
clipping function wouldn’t work and it would crash the program if you
try to draw out of bounds or the clipping function would work and
everything would get drawn. I mean, If I don’t even try to draw an out
of bounds pixel until the end of the line, why isn’t the beginning of
the line being drawn. (It works fine if everything is in bounds)

Anyhow I’ve babbled enough, I’d really appreciate some help getting the
needless core dumps to stop, all I have done is initialize the display,
that can’t possibly be my fault. Strangely though, I compiled testbitmap

and it doens’t dump core.

I setup a program that does nothing but initialize then screen, but yet
it core dumped. I added a putpixel function I wrote followed by an
SDL_WaitEvent. It will put the pixel to the screen, but after I cause an

event it still core dumps. (by the way is the mouse moving an event?,
the program dump core if I move the mouse)

Yes, mouse motion is an event.
Someone else mentioned that SDL is crashing on events. Can you send me
sample code that exhibits the problem?

Thanks,
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

I have included the source for the program that crashes. Note that
PP_RectFilled is my own function, but the program core dumps whether I call
that or not. It also core dumps if I leave out the SDL_WaitEvent and just
have a program that sets the screen. It will display the 640x480 window (I’m
using X11) and then core dump.

Sam Lantinga wrote:

I setup a program that does nothing but initialize then screen, but yet
it core dumped. I added a putpixel function I wrote followed by an
SDL_WaitEvent. It will put the pixel to the screen, but after I cause an

event it still core dumps. (by the way is the mouse moving an event?,
the program dump core if I move the mouse)

Yes, mouse motion is an event.
Someone else mentioned that SDL is crashing on events. Can you send me
sample code that exhibits the problem?

Thanks,
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software

“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec
-------------- next part --------------
#include <stdio.h>

#include “SDL/SDL.h”
#include “primitives.h”
#include “powerdraw.h”

int main()
{
SDL_Surface *screen;
SDL_Event event;

/* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(1);
}

/* Initialize the SDL library */
SDL_Init(SDL_INIT_VIDEO);

/* Clean up on exit */
atexit(SDL_Quit);

/* Initialize the display in a 640x480 32-bit mode */
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set 640x480x32 video mode: %s\n”, SDL_GetError());
exit(1);
}

PP_RectFilled (screen, 400, 256, 240, 400, SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00));

SDL_WaitEvent(&event);

SDL_Quit();
}

Ok, I feel like a complete idiot now :). I didn’t notice the second call to
SDL_INIT. I thought I just copied an pasted from the example in your web page.
Anyhow taking out the extra solved the problem.
Thanks for your time.

Sam Lantinga wrote:> > I have included the source for the program that crashes. Note that

PP_RectFilled is my own function, but the program core dumps whether I call
that or not. It also core dumps if I leave out the SDL_WaitEvent and just
have a program that sets the screen. It will display the 640x480 window (I’m
using X11) and then core dump.

It sounds like a problem in SDL_Quit().
It works fine on my system.

Try removing the second call to SDL_Init() and see if that fixes it.
Try removing the atexit() call, or the call to SDL_Quit() and see
if that fixes it.
If that still doesn’t work, add code to SDL_Quit() to see what’s
happening. Are you running the program as root?

See ya,
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software

“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec