SDL crash on exit

A 0xC000022 exception is thrown when my app quits.

The crash appears in the cleanup_output(void) function of SDL_main.c
the line
fclose(stdout);
produce a crash in fclose function of FCLOSE.C VC98 file.

Now I’m sure that there’s no more anything wrong with the setup of my
project (no ignored lib, clean win32 app, every linked lib recompiled
multithreaded dll)

What could it be ?

Thank you___________________________________________________________
Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com

It’s hard to say without seeing your sourcecode, but offhand I’d expect
there’s some memory corruption somewhere - freeing surfaces twice,
freeing surfaces that were never allocated, writing to memory you never
allocated, etc… these problems are annoying, because Windows can
sometimes let you get away with this long enough that where it crashes is
NOT what caused it to crash. For example, in one program I wrote, I was
accidentally freeing the VIDEO SURFACE - EVERY FRAME - and didn’t even
notice for days. Could you post the smallest program you have that can
reproduce this problem?

Chris wrote:> A 0xC000022 exception is thrown when my app quits.

The crash appears in the cleanup_output(void) function of SDL_main.c
the line
fclose(stdout);
produce a crash in fclose function of FCLOSE.C VC98 file.

Now I’m sure that there’s no more anything wrong with the setup of my
project (no ignored lib, clean win32 app, every linked lib recompiled
multithreaded dll)

What could it be ?

Thank you


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I’ve found a solution but don’t know if it’s the normal way (I’m really new
to SDL).

Now on linker setting I ignore libc and crashes are gone BUT boundschecker
reports many memory leaks.
Some of these leaks are in sdl, others are in microsoft libraries.
Don’t know if I can trust boundschecker in that case ??> ----- Original Message -----

From: tsm@accesscomm.ca (Tyler Montbriand)
To:
Sent: Wednesday, November 27, 2002 2:18 PM
Subject: Re: [SDL] SDL crash on exit

It’s hard to say without seeing your sourcecode, but offhand I’d expect
there’s some memory corruption somewhere - freeing surfaces twice,
freeing surfaces that were never allocated, writing to memory you never
allocated, etc… these problems are annoying, because Windows can
sometimes let you get away with this long enough that where it crashes is
NOT what caused it to crash. For example, in one program I wrote, I was
accidentally freeing the VIDEO SURFACE - EVERY FRAME - and didn’t even
notice for days. Could you post the smallest program you have that can
reproduce this problem?


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com

Chris wrote:

I’ve found a solution but don’t know if it’s the normal way (I’m really new
to SDL).

Now on linker setting I ignore libc and crashes are gone BUT boundschecker
reports many memory leaks.
Some of these leaks are in sdl, others are in microsoft libraries.
Don’t know if I can trust boundschecker in that case ??

Microsoft libraries leaking memory? What a shock. :wink: Seriously, though…
I’m uncertain if this has anything to do with libc. MSVC++ always gives
warnings about conflicting libraries and SDL, but in my experience those
warnings are harmless. My gut feeling still says you’re corrupting memory
somewhere, Windows just isn’t catching it. Again, I think it would be a good
idea for you to post your sourcecode; without it, all we can do is guess.

Microsoft libraries leaking memory? What a shock. :wink: Seriously,
though…
I’m uncertain if this has anything to do with libc. MSVC++ always gives
warnings about conflicting libraries and SDL, but in my experience those
warnings are harmless. My gut feeling still says you’re corrupting memory
somewhere, Windows just isn’t catching it. Again, I think it would be a
good
idea for you to post your sourcecode; without it, all we can do is guess.

It’s really too long (6000+ lines)…

But there’s something I don’t understand, when I was using sdl in a console
application (single threaded, sdlmain undefined) instead of win32 app, dll
multithreaded, sdlmain used.
I had no crash, no memory leaks with the same code (mine)… I Should have
had many problems and I had none ! What’s the reason ??


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com

----- Original Message -----
From: tsm@accesscomm.ca (Tyler Montbriand)
To:
Sent: Wednesday, November 27, 2002 2:55 PM
Subject: Re: [SDL] SDL crash on exit

Chris wrote:> ----- Original Message -----

From: “Corona688” <@Tyler_Montbriand>
To:
Sent: Wednesday, November 27, 2002 2:55 PM
Subject: Re: [SDL] SDL crash on exit

Microsoft libraries leaking memory? What a shock. :wink: Seriously,
though…
I’m uncertain if this has anything to do with libc. MSVC++ always gives
warnings about conflicting libraries and SDL, but in my experience those
warnings are harmless. My gut feeling still says you’re corrupting memory
somewhere, Windows just isn’t catching it. Again, I think it would be a
good
idea for you to post your sourcecode; without it, all we can do is guess.

It’s really too long (6000+ lines)…

Drat. :frowning: I don’t suppose you can reproduce the crash in a minimal program?

But there’s something I don’t understand, when I was using sdl in a console
application (single threaded, sdlmain undefined) instead of win32 app, dll
multithreaded, sdlmain used.
I had no crash, no memory leaks with the same code (mine)… I Should have
had many problems and I had none ! What’s the reason ??

It seems impossible to detect if, when, or why Windows will crash when memory
gets corrupted… if SDL crashes in a minimal program then something’s
definitely wrong with it, but if not I think the problem’s elsewhere… does
this program crash? (compile as multithreaded DLL as usual)

/testsdl.c/
#include <sdl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen=NULL;

if(SDL_Init(SDL_INIT_VIDEO)<0)
{
    printf("Couldn't init video!\n");
    return(-1);
}

screen=SDL_SetVideoMode(320,240,16,SDL_ANYFORMAT);
if(screen==NULL)
{
    printf("Couldn't set video mode!\n");
    SDL_Quit();
    return(-1);
}

SDL_FillRect(screen,NULL,SDL_MapRGB(255,0,0));

SDL_Flip(screen);
SDL_Delay(1000);

SDL_Quit();

return(0);

}
/end testsdl.c/

Maybe you already had them they just weren’t
showing up.

For example, if you have a pointer problem it
may only show up in certain conditions.–
Paulo Pinto

----- Original Message -----
From: jlsfjs@yahoo.fr (Chris)
To:
Sent: Wednesday, November 27, 2002 2:57 PM
Subject: Re: [SDL] SDL crash on exit

----- Original Message -----
From: “Corona688”
To:
Sent: Wednesday, November 27, 2002 2:55 PM
Subject: Re: [SDL] SDL crash on exit

Microsoft libraries leaking memory? What a shock. :wink: Seriously,
though…
I’m uncertain if this has anything to do with libc. MSVC++ always gives
warnings about conflicting libraries and SDL, but in my experience those
warnings are harmless. My gut feeling still says you’re corrupting
memory

somewhere, Windows just isn’t catching it. Again, I think it would be a
good
idea for you to post your sourcecode; without it, all we can do is
guess.

It’s really too long (6000+ lines)…

But there’s something I don’t understand, when I was using sdl in a
console
application (single threaded, sdlmain undefined) instead of win32 app, dll
multithreaded, sdlmain used.
I had no crash, no memory leaks with the same code (mine)… I Should have
had many problems and I had none ! What’s the reason ??


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I can’t compile it :
error C2660: ‘SDL_MapRGB’ : function does not take 3 parameters> ----- Original Message -----

From: tsm@accesscomm.ca (Tyler Montbriand)
To:
Sent: Wednesday, November 27, 2002 4:18 PM
Subject: Re: [SDL] SDL crash on exit

/testsdl.c/
#include <sdl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen=NULL;

if(SDL_Init(SDL_INIT_VIDEO)<0)
{
    printf("Couldn't init video!\n");
    return(-1);
}

screen=SDL_SetVideoMode(320,240,16,SDL_ANYFORMAT);
if(screen==NULL)
{
    printf("Couldn't set video mode!\n");
    SDL_Quit();
    return(-1);
}

SDL_FillRect(screen,NULL,SDL_MapRGB(255,0,0));

SDL_Flip(screen);
SDL_Delay(1000);

SDL_Quit();

return(0);

}
/end testsdl.c/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com

The compiler is right

It is SDL_MapRGB (screen->format, 255,0,0)–
Paulo Pinto

----- Original Message -----
From: jlsfjs@yahoo.fr (Chris)
To:
Sent: Wednesday, November 27, 2002 4:01 PM
Subject: Re: [SDL] SDL crash on exit

I can’t compile it :
error C2660: ‘SDL_MapRGB’ : function does not take 3 parameters

----- Original Message -----
From: “Corona688”
To:
Sent: Wednesday, November 27, 2002 4:18 PM
Subject: Re: [SDL] SDL crash on exit

/testsdl.c/
#include <sdl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen=NULL;

if(SDL_Init(SDL_INIT_VIDEO)<0)
{
    printf("Couldn't init video!\n");
    return(-1);
}

screen=SDL_SetVideoMode(320,240,16,SDL_ANYFORMAT);
if(screen==NULL)
{
    printf("Couldn't set video mode!\n");
    SDL_Quit();
    return(-1);
}

SDL_FillRect(screen,NULL,SDL_MapRGB(255,0,0));

SDL_Flip(screen);
SDL_Delay(1000);

SDL_Quit();

return(0);

}
/end testsdl.c/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

The code doesn’t crash, with or without ignoring msvcrt.lib

One leak is found in sdl_events.c (line 593)
and a wrong HWND handle is passed to GetWindowRect(SDL_Window, &size); (line
413)
Nothing harmfull I presume…

definitely I must have a bug in my app, maybe writing past and array
boundaries… Will be hard to find !> ----- Original Message -----

From: tsm@accesscomm.ca (Tyler Montbriand)
To:
Sent: Wednesday, November 27, 2002 4:18 PM
Subject: Re: [SDL] SDL crash on exit

/testsdl.c/
#include <sdl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen=NULL;

if(SDL_Init(SDL_INIT_VIDEO)<0)
{
    printf("Couldn't init video!\n");
    return(-1);
}

screen=SDL_SetVideoMode(320,240,16,SDL_ANYFORMAT);
if(screen==NULL)
{
    printf("Couldn't set video mode!\n");
    SDL_Quit();
    return(-1);
}

SDL_FillRect(screen,NULL,SDL_MapRGB(255,0,0));

SDL_Flip(screen);
SDL_Delay(1000);

SDL_Quit();

return(0);

}
/end testsdl.c/


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com

If you’re under Win / Mac
don’t make a call to SDL_Quit()
It’s already done by module SDLmain> The code doesn’t crash, with or without ignoring msvcrt.lib

One leak is found in sdl_events.c (line 593)
and a wrong HWND handle is passed to GetWindowRect(SDL_Window, &size);
(line
413)
Nothing harmfull I presume…

definitely I must have a bug in my app, maybe writing past and array
boundaries… Will be hard to find !

----- Original Message -----
From: “Corona688”
To:
Sent: Wednesday, November 27, 2002 4:18 PM
Subject: Re: [SDL] SDL crash on exit

/testsdl.c/
#include <sdl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen=NULL;

if(SDL_Init(SDL_INIT_VIDEO)<0)
{
    printf("Couldn't init video!\n");
    return(-1);
}

screen=SDL_SetVideoMode(320,240,16,SDL_ANYFORMAT);
if(screen==NULL)
{
    printf("Couldn't set video mode!\n");
    SDL_Quit();
    return(-1);
}

SDL_FillRect(screen,NULL,SDL_MapRGB(255,0,0));

SDL_Flip(screen);
SDL_Delay(1000);

SDL_Quit();

return(0);

}
/end testsdl.c/


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


THESNIERES Sylvain
Darksoft Inc.

@Sylvain_THESNIERES

If you’re under Win / Mac
don’t make a call to SDL_Quit()
It’s already done by module SDLmain

hmmm, I dunno wether it’s already called in SDLmain for you but I’m
pretty sure it does no harm to call it in your main() whatever your OS
is. Wether you call it yourself or use atexit() is up to you, but you
really should call it on all OSes.

I don’t know what the problem is in this case, but it’s surely not
because he’s calling SDL_Quit().

See ya,
Ga?tan.On Thu, 2002-11-28 at 08:02, THESNIERES Sylvain wrote:

The code doesn’t crash, with or without ignoring msvcrt.lib

One leak is found in sdl_events.c (line 593)
and a wrong HWND handle is passed to GetWindowRect(SDL_Window, &size);
(line
413)
Nothing harmfull I presume…

definitely I must have a bug in my app, maybe writing past and array
boundaries… Will be hard to find !

----- Original Message -----
From: “Corona688”
To:
Sent: Wednesday, November 27, 2002 4:18 PM
Subject: Re: [SDL] SDL crash on exit

/testsdl.c/
#include <sdl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen=NULL;

if(SDL_Init(SDL_INIT_VIDEO)<0)
{
    printf("Couldn't init video!\n");
    return(-1);
}

screen=SDL_SetVideoMode(320,240,16,SDL_ANYFORMAT);
if(screen==NULL)
{
    printf("Couldn't set video mode!\n");
    SDL_Quit();
    return(-1);
}

SDL_FillRect(screen,NULL,SDL_MapRGB(255,0,0));

SDL_Flip(screen);
SDL_Delay(1000);

SDL_Quit();

return(0);

}
/end testsdl.c/

I’m having a lot of fun with seg faults when exitting my game at the moment.
A few things to look for,

  1. Make sure you’re closing all your file pointers (if any). Sometimes I
    just forget to do it!

  2. Make sure you’re freeing any allocated memory (via malloc) before
    exitting

  3. If you’re performing SDL_CreateSurface() make sure you’re freeing those.> -----Original Message-----

From: Chris [SMTP:jlsfjs at yahoo.fr]
Sent: Wednesday, November 27, 2002 5:39 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL crash on exit

The code doesn’t crash, with or without ignoring msvcrt.lib

One leak is found in sdl_events.c (line 593)
and a wrong HWND handle is passed to GetWindowRect(SDL_Window, &size);
(line
413)
Nothing harmfull I presume…

definitely I must have a bug in my app, maybe writing past and array
boundaries… Will be hard to find !

----- Original Message -----
From: “Corona688”
To:
Sent: Wednesday, November 27, 2002 4:18 PM
Subject: Re: [SDL] SDL crash on exit

/testsdl.c/
#include <sdl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen=NULL;

if(SDL_Init(SDL_INIT_VIDEO)<0)
{
    printf("Couldn't init video!\n");
    return(-1);
}

screen=SDL_SetVideoMode(320,240,16,SDL_ANYFORMAT);
if(screen==NULL)
{
    printf("Couldn't set video mode!\n");
    SDL_Quit();
    return(-1);
}

SDL_FillRect(screen,NULL,SDL_MapRGB(255,0,0));

SDL_Flip(screen);
SDL_Delay(1000);

SDL_Quit();

return(0);

}
/end testsdl.c/


Do You Yahoo!? – Une adresse @yahoo.fr gratuite et en fran?ais !
Yahoo! Mail : http://fr.mail.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

.sophos.3.63.11.25.

I’ve found MSS (Memory Supervision System) to be very helpful in finding such
problems. You can get it at:

http://hem1.passagen.se/blizzar/mss/index.html.

JeffOn Thursday 28 November 2002 02:50 am, you wrote:

  1. Make sure you’re closing all your file pointers (if any). Sometimes I
    just forget to do it!

  2. Make sure you’re freeing any allocated memory (via malloc) before
    exitting

  3. If you’re performing SDL_CreateSurface() make sure you’re freeing those.

I’m having a lot of fun with seg faults when exitting my game at the
moment. A few things to look for,

  1. Make sure you’re closing all your file pointers (if any). Sometimes
    I just forget to do it!

  2. Make sure you’re freeing any allocated memory (via malloc) before
    exitting

  3. If you’re performing SDL_CreateSurface() make sure you’re freeing
    those.

What helped me once, was to sleep 1 sec before finally exiting the
program :)On Thu, 28 Nov 2002 10:50:28 -0000 “Sweeney, Steven (FNB)” wrote:

@Florian_Schmidt
http://mistatapas.ath.cx

I already tried.
If I make a return a the end of main()
with atexit(SDL_Quit), the program crashes,
and if I quit with exit(some_code), I doesn’t.

so if you uses atexit, I suggest ending the program with a call to exit

It’s probably because CRT routines clean memory BEFORE calling any "atexit"
routine, so when SDL_Quit is called, memory is already freed and SDL can’t
know it, so it try to free and it crashes. I had the same problem with some
of my libraries who allocated at the start but free automatiquely at the end
with atexit. It seems that “returning form main” and calling “exit” don’t use
the same way for quitting a program, particularly for memory cleaning.

sylvain> > If you’re under Win / Mac

don’t make a call to SDL_Quit()
It’s already done by module SDLmain

hmmm, I dunno wether it’s already called in SDLmain for you but I’m
pretty sure it does no harm to call it in your main() whatever your OS
is. Wether you call it yourself or use atexit() is up to you, but you
really should call it on all OSes.

I don’t know what the problem is in this case, but it’s surely not
because he’s calling SDL_Quit().

See ya,
Ga?tan.

The code doesn’t crash, with or without ignoring msvcrt.lib

One leak is found in sdl_events.c (line 593)
and a wrong HWND handle is passed to GetWindowRect(SDL_Window, &size);
(line
413)
Nothing harmfull I presume…

definitely I must have a bug in my app, maybe writing past and array
boundaries… Will be hard to find !

----- Original Message -----
From: “Corona688”
To:
Sent: Wednesday, November 27, 2002 4:18 PM
Subject: Re: [SDL] SDL crash on exit

/testsdl.c/
#include <sdl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen=NULL;

if(SDL_Init(SDL_INIT_VIDEO)<0)
{
    printf("Couldn't init video!\n");
    return(-1);
}

screen=SDL_SetVideoMode(320,240,16,SDL_ANYFORMAT);
if(screen==NULL)
{
    printf("Couldn't set video mode!\n");
    SDL_Quit();
    return(-1);
}

SDL_FillRect(screen,NULL,SDL_MapRGB(255,0,0));

SDL_Flip(screen);
SDL_Delay(1000);

SDL_Quit();

return(0);

}
/end testsdl.c/


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl