Free( ptr ) causes SDL Parachute Deployed?

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute has been
deployed. i have traced the reason to the line: “free( ptr );”. ive checked
to make sure the ptr is not null, and it hasnt been freed anywhere else
before - and the malloc was successful. its always the same pointer too,
which is odd. if i comment out the “free( ptr );” line the program runs
through to the end with no errors. what could be causing a "free( ptr )"
statement to mess up SDL?

  • jeremiah

It may be that some part of your program is trying to reference that pointer
after it has been freed. That is, you may be freeing it before its actually
been used.>From: “Martell, Jeremiah”

Reply-To: sdl at libsdl.org
To: “‘sdl at libsdl.org’”
Subject: [SDL] free( ptr ) causes SDL Parachute Deployed?
Date: Sat, 1 Feb 2003 02:37:10 -0500

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute has been
deployed. i have traced the reason to the line: “free( ptr );”. ive checked
to make sure the ptr is not null, and it hasnt been freed anywhere else
before - and the malloc was successful. its always the same pointer too,
which is odd. if i comment out the “free( ptr );” line the program runs
through to the end with no errors. what could be causing a "free( ptr )"
statement to mess up SDL?

  • jeremiah

Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail

free( ptr ) causes SDL Parachute Deployed?just because the pointer isnt null that doesnt mean its a valid memory address. The pointer could be uninitialized, or something might be changing its address to an address outside of the allowable address range for your program. It could also be a problem of memory corruption.----- Original Message -----
From: Martell, Jeremiah
To: 'sdl at libsdl.org
Sent: Friday, January 31, 2003 11:37 PM
Subject: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute has been deployed. i have traced the reason to the line: "free( ptr );". ive checked to make sure the ptr is not null, and it hasnt been freed anywhere else before - and the malloc was successful. its always the same pointer too, which is odd. if i comment out the "free( ptr );" line the program runs through to the end with no errors. what could be causing a "free( ptr )" statement to mess up SDL? 
  • jeremiah

the ptr points to my image struct that contains three values, Uint32
width, Uint32 height, and Uint8 *pixels. a function called "createImage"
allocates memory for a pointer to an instance of the struct. then allocates
memory for the Uint8 *pixels and initializes it as well. i know its
successful because in the main loop, my drawImage function successfully
draws it to screen. at the end of my program i have a freeImage function
that frees the Uint8 *pixels, and then frees the entire struct.

void freeImage( struct myImage *ptr )
{
myIMAGE_numOfImages–;
free( ptr->pixels );
free( ptr );
}

other images are successfully loaded, drawn, and freed in the exact same
manner. its only one image that causes the program to end when it tries to
free its ptr->pixels. but i know its loaded successfully because i can draw
it to screen.

this problem is baffling me.

  • jeremiah> ----- Original Message -----

From: Atrix Wolfe
To: sdl at libsdl.org
Sent: 2/1/2003 3:07 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

just because the pointer isnt null that doesnt mean its a valid memory
address. The pointer could be uninitialized, or something might be
changing its address to an address outside of the allowable address
range for your program. It could also be a problem of memory
corruption.

----- Original Message -----
From: Martell, Jeremiah mailto:Martell_Jeremiah
To: ‘sdl at libsdl.org’ <mailto:‘sdl at libsdl.org’>
Sent: Friday, January 31, 2003 11:37 PM
Subject: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute has
been deployed. i have traced the reason to the line: “free( ptr );”. ive
checked to make sure the ptr is not null, and it hasnt been freed
anywhere else before - and the malloc was successful. its always the
same pointer too, which is odd. if i comment out the “free( ptr );” line
the program runs through to the end with no errors. what could be
causing a “free( ptr )” statement to mess up SDL?

  • jeremiah

Hm. Are you:
-mixing malloc/free-style and new/delete-style calls?
-Sharing one instance of said data between several structures?
-Using any library that overloads malloc/free(I HATE that kind of
problem)?

If not any of those, then perhaps some function somewhere is writing to
memory it shouldn’t, and it only finds out after it tries to free it…
if you’re programming in Win32, by the way, Win32 will let you get away
with any number of bad memory things and get away with it.

“Martell, Jeremiah” wrote:>

the ptr points to my image struct that contains three values, Uint32
width, Uint32 height, and Uint8 *pixels. a function called
"createImage" allocates memory for a pointer to an instance of the
struct. then allocates memory for the Uint8 *pixels and initializes it
as well. i know its successful because in the main loop, my drawImage
function successfully draws it to screen. at the end of my program i
have a freeImage function that frees the Uint8 *pixels, and then frees
the entire struct.

void freeImage( struct myImage *ptr )
{
myIMAGE_numOfImages–;
free( ptr->pixels );
free( ptr );
}

other images are successfully loaded, drawn, and freed in the exact
same manner. its only one image that causes the program to end when it
tries to free its ptr->pixels. but i know its loaded successfully
because i can draw it to screen.

this problem is baffling me.

  • jeremiah

-----Original Message-----
From: Atrix Wolfe
To: sdl at libsdl.org
Sent: 2/1/2003 3:07 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

just because the pointer isnt null that doesnt mean its a valid memory

address. The pointer could be uninitialized, or something might be
changing its address to an address outside of the allowable address
range for your program. It could also be a problem of memory
corruption.

----- Original Message -----
From: Martell, Jeremiah <mailto:jmarte01 at bellarmine.edu>
To: ‘sdl at libsdl.org’ <mailto:‘sdl at libsdl.org’>
Sent: Friday, January 31, 2003 11:37 PM
Subject: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute has
been deployed. i have traced the reason to the line: “free( ptr );”.
ive
checked to make sure the ptr is not null, and it hasnt been freed
anywhere else before - and the malloc was successful. its always the
same pointer too, which is odd. if i comment out the "free( ptr );"
line
the program runs through to the end with no errors. what could be
causing a “free( ptr )” statement to mess up SDL?

  • jeremiah

hello,

while i do use both malloc/free and new/delete, all the memory allocation
needs of my images use malloc/free.

each structure uses its own data, no sharing involved.

only library im using is ZLIB, and im not sure if they overload
malloc/free or not.

im programming for Win32, using the MinGW compiler, with SDL, and ZLIB.

well, i found a way to fix the error, but it doesnt make any sense to me
at all…

in my program i do the following:

  1. load “alpha.png” image (font)

  2. load “alpha2.png” image (font)

  3. load “test.png” image.

  4. load “smiley.png” image.

  5. load “smileyOLD.png” image

  6. main loop, draw all three images to screen, and also two strings
    with each font.

  7. free all fonts

  8. free “test.png”

  9. free “smiley.png”

  10. free smileyOLD.png"

it seems that if i reverse the order i load “smiley.png” and
"smileyOLD.png", then free( ptr ) ends my program at the end. so: switching
steps 4 & 5 above would cause step 10 to end the program. why is this?

ok loading orders:
“test.png”, then “smiley.png”, then “smileyOLD.png”.
“smileyOLD.png”, then “smile.png”, then “test.png”.
“smileyOLD.png”, then “test.png”, then “smile.png”.
“smile.png”, then “smileOLD.png”, then “test.png”.
“smile.png”, then “test.png”, then “smileOLD.png”.

NOT-ok loading orders:
“test.png”, then “smileyOLD.png”, then “smile.png”.

when i load the three images in NOT-ok order (the only one out of the six
possible combinations that causes the error), the program ends when i try to
free “smileyOLD.png”. regardless of whether i free “test.png” or "smile.png"
before or afterward, its just “smileyOLD.png” that causes the program to
end.

another odd piece of this puzzle is if i remove step 2, then the program
runs fine, and “smileyOLD.png” causes no trouble at all. also, if i add in
other steps between 2 and 3 to load extra fonts, then the program also runs
fine, and “smileyOLD.png” doesnt cause any trouble.

it seems the only way this problem occurs is when i load exactly 2 fonts
(order of loading fonts doesnt matter, i checked. only when i load 2 fonts
exactly), and then load the 3 images in the exact specific order. what in
the world could be causing this?

  • jeremiah> ----- Original Message -----

From: Corona688
To: sdl at libsdl.org
Sent: 2/1/2003 6:38 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

Hm. Are you:
-mixing malloc/free-style and new/delete-style calls?
-Sharing one instance of said data between several structures?
-Using any library that overloads malloc/free(I HATE that kind of
problem)?

If not any of those, then perhaps some function somewhere is writing to
memory it shouldn’t, and it only finds out after it tries to free it…
if you’re programming in Win32, by the way, Win32 will let you get away
with any number of bad memory things and get away with it.

“Martell, Jeremiah” wrote:

the ptr points to my image struct that contains three values, Uint32
width, Uint32 height, and Uint8 *pixels. a function called
"createImage" allocates memory for a pointer to an instance of the
struct. then allocates memory for the Uint8 *pixels and initializes it
as well. i know its successful because in the main loop, my drawImage
function successfully draws it to screen. at the end of my program i
have a freeImage function that frees the Uint8 *pixels, and then frees
the entire struct.

void freeImage( struct myImage *ptr )
{
myIMAGE_numOfImages–;
free( ptr->pixels );
free( ptr );
}

other images are successfully loaded, drawn, and freed in the exact
same manner. its only one image that causes the program to end when it
tries to free its ptr->pixels. but i know its loaded successfully
because i can draw it to screen.

this problem is baffling me.

  • jeremiah

-----Original Message-----
From: Atrix Wolfe
To: sdl at libsdl.org
Sent: 2/1/2003 3:07 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

just because the pointer isnt null that doesnt mean its a valid memory

address. The pointer could be uninitialized, or something might be
changing its address to an address outside of the allowable address
range for your program. It could also be a problem of memory
corruption.

----- Original Message -----
From: Martell, Jeremiah mailto:Martell_Jeremiah
To: ‘sdl at libsdl.org’ <mailto:‘sdl at libsdl.org’>
Sent: Friday, January 31, 2003 11:37 PM
Subject: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute has
been deployed. i have traced the reason to the line: “free( ptr );”.
ive
checked to make sure the ptr is not null, and it hasnt been freed
anywhere else before - and the malloc was successful. its always the
same pointer too, which is odd. if i comment out the "free( ptr );"
line
the program runs through to the end with no errors. what could be
causing a “free( ptr )” statement to mess up SDL?

  • jeremiah

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

RE: RE: [SDL] free( ptr ) causes SDL Parachute Deployed?sounds to me EXACTLY like a memory corruption issue. Something probably isnt allocating enough memory and is going out of its bounds or something of that nature. Memory corruption is the cause of all these “i have to do it in this order but not this order” bugs, and bugs where you say “i can see that this pointer is fine but when i delete it, it throws an exception” because the address is over-written by something else.----- Original Message -----
From: Martell, Jeremiah
To: 'sdl at libsdl.org
Sent: Saturday, February 01, 2003 5:48 PM
Subject: RE: RE: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

while i do use both malloc/free and new/delete, all the memory allocation needs of my images use malloc/free. 

each structure uses its own data, no sharing involved. 

only library im using is ZLIB, and im not sure if they overload malloc/free or not. 

im programming for Win32, using the MinGW compiler, with SDL, and ZLIB. 

well, i found a way to fix the error, but it doesnt make any sense to me at all... 

in my program i do the following: 
  1. load “alpha.png” image (font)

  2. load “alpha2.png” image (font)

  3. load “test.png” image.

  4. load “smiley.png” image.

  5. load “smileyOLD.png” image

  6. main loop, draw all three images to screen, and also two strings
    with each font.

  7. free all fonts

  8. free “test.png”

  9. free “smiley.png”

  10. free smileyOLD.png"

it seems that if i reverse the order i load “smiley.png” and “smileyOLD.png”, then free( ptr ) ends my program at the end. so: switching steps 4 & 5 above would cause step 10 to end the program. why is this?

ok loading orders:
“test.png”, then “smiley.png”, then “smileyOLD.png”.
“smileyOLD.png”, then “smile.png”, then “test.png”.
“smileyOLD.png”, then “test.png”, then “smile.png”.
“smile.png”, then “smileOLD.png”, then “test.png”.
“smile.png”, then “test.png”, then “smileOLD.png”.

NOT-ok loading orders:
“test.png”, then “smileyOLD.png”, then “smile.png”.

when i load the three images in NOT-ok order (the only one out of the six possible combinations that causes the error), the program ends when i try to free “smileyOLD.png”. regardless of whether i free “test.png” or “smile.png” before or afterward, its just “smileyOLD.png” that causes the program to end.

another odd piece of this puzzle is if i remove step 2, then the program runs fine, and “smileyOLD.png” causes no trouble at all. also, if i add in other steps between 2 and 3 to load extra fonts, then the program also runs fine, and “smileyOLD.png” doesnt cause any trouble.

it seems the only way this problem occurs is when i load exactly 2 fonts (order of loading fonts doesnt matter, i checked. only when i load 2 fonts exactly), and then load the 3 images in the exact specific order. what in the world could be causing this?

  • jeremiah

-----Original Message-----
From: Corona688
To: sdl at libsdl.org
Sent: 2/1/2003 6:38 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

Hm. Are you:
-mixing malloc/free-style and new/delete-style calls?
-Sharing one instance of said data between several structures?
-Using any library that overloads malloc/free(I HATE that kind of
problem)?

If not any of those, then perhaps some function somewhere is writing to
memory it shouldn’t, and it only finds out after it tries to free it…
if you’re programming in Win32, by the way, Win32 will let you get away
with any number of bad memory things and get away with it.

“Martell, Jeremiah” wrote:

the ptr points to my image struct that contains three values, Uint32
width, Uint32 height, and Uint8 *pixels. a function called
"createImage" allocates memory for a pointer to an instance of the
struct. then allocates memory for the Uint8 *pixels and initializes it
as well. i know its successful because in the main loop, my drawImage
function successfully draws it to screen. at the end of my program i
have a freeImage function that frees the Uint8 *pixels, and then frees
the entire struct.

void freeImage( struct myImage *ptr )
{
myIMAGE_numOfImages–;
free( ptr->pixels );
free( ptr );
}

other images are successfully loaded, drawn, and freed in the exact
same manner. its only one image that causes the program to end when it
tries to free its ptr->pixels. but i know its loaded successfully
because i can draw it to screen.

this problem is baffling me.

  • jeremiah

-----Original Message-----
From: Atrix Wolfe
To: sdl at libsdl.org
Sent: 2/1/2003 3:07 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

just because the pointer isnt null that doesnt mean its a valid memory

address. The pointer could be uninitialized, or something might be
changing its address to an address outside of the allowable address
range for your program. It could also be a problem of memory
corruption.

----- Original Message -----
From: Martell, Jeremiah <mailto:jmarte01 at bellarmine.edu>
To: ‘sdl at libsdl.org’ <mailto:‘sdl at libsdl.org’>
Sent: Friday, January 31, 2003 11:37 PM
Subject: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute has
been deployed. i have traced the reason to the line: “free( ptr );”.
ive
checked to make sure the ptr is not null, and it hasnt been freed
anywhere else before - and the malloc was successful. its always the
same pointer too, which is odd. if i comment out the "free( ptr );"
line
the program runs through to the end with no errors. what could be
causing a “free( ptr )” statement to mess up SDL?

  • jeremiah

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

is there anyway to detect where this is happening? i guess i could go
through all my code and try and find out where, but that could be pretty
tedious. especially since all the code works and all the images/fonts are
loading and displaying correctly. is there any easy way to find the problem,
or at least narrow it down?

  • jeremiah> ----- Original Message -----

From: Atrix Wolfe
To: sdl at libsdl.org
Sent: 2/1/2003 9:13 PM
Subject: Re: RE: [SDL] free( ptr ) causes SDL Parachute Deployed?

sounds to me EXACTLY like a memory corruption issue. Something probably
isnt allocating enough memory and is going out of its bounds or
something of that nature. Memory corruption is the cause of all these
"i have to do it in this order but not this order" bugs, and bugs where
you say “i can see that this pointer is fine but when i delete it, it
throws an exception” because the address is over-written by something
else.

----- Original Message -----
From: Martell, Jeremiah mailto:Martell_Jeremiah
To: ‘sdl at libsdl.org’ <mailto:‘sdl at libsdl.org’>
Sent: Saturday, February 01, 2003 5:48 PM
Subject: RE: RE: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

while i do use both malloc/free and new/delete, all the memory
allocation needs of my images use malloc/free.

each structure uses its own data, no sharing involved.

only library im using is ZLIB, and im not sure if they overload
malloc/free or not.

im programming for Win32, using the MinGW compiler, with SDL, and
ZLIB.

well, i found a way to fix the error, but it doesnt make any sense to
me at all…

in my program i do the following:

  1. load “alpha.png” image (font)

  2. load “alpha2.png” image (font)

  3. load “test.png” image.

  4. load “smiley.png” image.

  5. load “smileyOLD.png” image

  6. main loop, draw all three images to screen, and also two strings
    with each font.

  7. free all fonts

  8. free “test.png”

  9. free “smiley.png”

  10. free smileyOLD.png"

it seems that if i reverse the order i load “smiley.png” and
"smileyOLD.png", then free( ptr ) ends my program at the end. so:
switching steps 4 & 5 above would cause step 10 to end the program. why
is this?

ok loading orders:
“test.png”, then “smiley.png”, then “smileyOLD.png”.
“smileyOLD.png”, then “smile.png”, then “test.png”.
“smileyOLD.png”, then “test.png”, then “smile.png”.
“smile.png”, then “smileOLD.png”, then “test.png”.
“smile.png”, then “test.png”, then “smileOLD.png”.

NOT-ok loading orders:
“test.png”, then “smileyOLD.png”, then “smile.png”.

when i load the three images in NOT-ok order (the only one out of the
six possible combinations that causes the error), the program ends when
i try to free “smileyOLD.png”. regardless of whether i free "test.png"
or “smile.png” before or afterward, its just “smileyOLD.png” that causes
the program to end.

another odd piece of this puzzle is if i remove step 2, then the program
runs fine, and “smileyOLD.png” causes no trouble at all. also, if i add
in other steps between 2 and 3 to load extra fonts, then the program
also runs fine, and “smileyOLD.png” doesnt cause any trouble.

it seems the only way this problem occurs is when i load exactly 2 fonts
(order of loading fonts doesnt matter, i checked. only when i load 2
fonts exactly), and then load the 3 images in the exact specific order.
what in the world could be causing this?

  • jeremiah

-----Original Message-----
From: Corona688
To: sdl at libsdl.org
Sent: 2/1/2003 6:38 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

Hm. Are you:
-mixing malloc/free-style and new/delete-style calls?
-Sharing one instance of said data between several structures?
-Using any library that overloads malloc/free(I HATE that kind of
problem)?

If not any of those, then perhaps some function somewhere is writing to
memory it shouldn’t, and it only finds out after it tries to free it…
if you’re programming in Win32, by the way, Win32 will let you get away
with any number of bad memory things and get away with it.

“Martell, Jeremiah” wrote:

the ptr points to my image struct that contains three values, Uint32

width, Uint32 height, and Uint8 *pixels. a function called
"createImage" allocates memory for a pointer to an instance of the
struct. then allocates memory for the Uint8 *pixels and initializes it

as well. i know its successful because in the main loop, my drawImage
function successfully draws it to screen. at the end of my program i
have a freeImage function that frees the Uint8 *pixels, and then frees

the entire struct.

void freeImage( struct myImage *ptr )
{
myIMAGE_numOfImages–;
free( ptr->pixels );
free( ptr );
}

other images are successfully loaded, drawn, and freed in the exact
same manner. its only one image that causes the program to end when it

tries to free its ptr->pixels. but i know its loaded successfully
because i can draw it to screen.

this problem is baffling me.

  • jeremiah

-----Original Message-----
From: Atrix Wolfe
To: sdl at libsdl.org
Sent: 2/1/2003 3:07 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

just because the pointer isnt null that doesnt mean its a valid memory

address. The pointer could be uninitialized, or something might be
changing its address to an address outside of the allowable address
range for your program. It could also be a problem of memory
corruption.

----- Original Message -----
From: Martell, Jeremiah < mailto:@Martell_Jeremiah
mailto:Martell_Jeremiah >
To: ‘sdl at libsdl.org’ < mailto:‘sdl at libsdl.org
<mailto:‘sdl at libsdl.org’> >
Sent: Friday, January 31, 2003 11:37 PM
Subject: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute has
been deployed. i have traced the reason to the line: “free( ptr );”.
ive
checked to make sure the ptr is not null, and it hasnt been freed
anywhere else before - and the malloc was successful. its always the
same pointer too, which is odd. if i comment out the "free( ptr );"
line
the program runs through to the end with no errors. what could be
causing a “free( ptr )” statement to mess up SDL?

  • jeremiah

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

I haven’t been following this thread too carefully, but I saw something
about memory corruption and trying to locate where it happens. If you’re
running on an x86 Linux box, or at least can get your program to run on
one, I’d recommend valgrind. It’s a gpl’d project that wraps a lot of
common c functions, including malloc and free and reports memory leaks,
invalid reads, and all that. It’s the perfect tool to track down memory
leaks when writing games and multimedia applications.On Sat, 2003-02-01 at 22:03, Martell, Jeremiah wrote:

is there anyway to detect where this is happening? i guess i could go
through all my code and try and find out where, but that could be
pretty tedious. especially since all the code works and all the
images/fonts are loading and displaying correctly. is there any easy
way to find the problem, or at least narrow it down?

  • jeremiah

-----Original Message-----
From: Atrix Wolfe
To: sdl at libsdl.org
Sent: 2/1/2003 9:13 PM
Subject: Re: RE: [SDL] free( ptr ) causes SDL Parachute Deployed?

sounds to me EXACTLY like a memory corruption issue. Something
probably
isnt allocating enough memory and is going out of its bounds or
something of that nature. Memory corruption is the cause of all these
"i have to do it in this order but not this order" bugs, and bugs
where
you say “i can see that this pointer is fine but when i delete it, it
throws an exception” because the address is over-written by something
else.

----- Original Message -----
From: Martell, Jeremiah <mailto:jmarte01 at bellarmine.edu>
To: ‘sdl at libsdl.org’ <mailto:‘sdl at libsdl.org’>
Sent: Saturday, February 01, 2003 5:48 PM
Subject: RE: RE: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

while i do use both malloc/free and new/delete, all the memory
allocation needs of my images use malloc/free.

each structure uses its own data, no sharing involved.

only library im using is ZLIB, and im not sure if they overload
malloc/free or not.

im programming for Win32, using the MinGW compiler, with SDL, and
ZLIB.

well, i found a way to fix the error, but it doesnt make any sense
to
me at all…

in my program i do the following:

  1. load “alpha.png” image (font)

  2. load “alpha2.png” image (font)

  3. load “test.png” image.

  4. load “smiley.png” image.

  5. load “smileyOLD.png” image

  6. main loop, draw all three images to screen, and also two strings
    with each font.

  7. free all fonts

  8. free “test.png”

  9. free “smiley.png”

  10. free smileyOLD.png"

it seems that if i reverse the order i load “smiley.png” and
"smileyOLD.png", then free( ptr ) ends my program at the end. so:
switching steps 4 & 5 above would cause step 10 to end the program.
why
is this?

ok loading orders:
“test.png”, then “smiley.png”, then “smileyOLD.png”.
“smileyOLD.png”, then “smile.png”, then “test.png”.
“smileyOLD.png”, then “test.png”, then “smile.png”.
“smile.png”, then “smileOLD.png”, then “test.png”.
“smile.png”, then “test.png”, then “smileOLD.png”.

NOT-ok loading orders:
“test.png”, then “smileyOLD.png”, then “smile.png”.

when i load the three images in NOT-ok order (the only one out of the
six possible combinations that causes the error), the program ends
when
i try to free “smileyOLD.png”. regardless of whether i free "test.png"
or “smile.png” before or afterward, its just “smileyOLD.png” that
causes
the program to end.

another odd piece of this puzzle is if i remove step 2, then the
program
runs fine, and “smileyOLD.png” causes no trouble at all. also, if i
add
in other steps between 2 and 3 to load extra fonts, then the program
also runs fine, and “smileyOLD.png” doesnt cause any trouble.

it seems the only way this problem occurs is when i load exactly 2
fonts
(order of loading fonts doesnt matter, i checked. only when i load 2
fonts exactly), and then load the 3 images in the exact specific
order.
what in the world could be causing this?

  • jeremiah

-----Original Message-----
From: Corona688
To: sdl at libsdl.org
Sent: 2/1/2003 6:38 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

Hm. Are you:
-mixing malloc/free-style and new/delete-style calls?
-Sharing one instance of said data between several structures?
-Using any library that overloads malloc/free(I HATE that kind of
problem)?

If not any of those, then perhaps some function somewhere is writing
to
memory it shouldn’t, and it only finds out after it tries to free
it…
if you’re programming in Win32, by the way, Win32 will let you get
away
with any number of bad memory things and get away with it.

“Martell, Jeremiah” wrote:

the ptr points to my image struct that contains three values,
Uint32

width, Uint32 height, and Uint8 *pixels. a function called
"createImage" allocates memory for a pointer to an instance of the
struct. then allocates memory for the Uint8 *pixels and initializes
it

as well. i know its successful because in the main loop, my
drawImage
function successfully draws it to screen. at the end of my program i
have a freeImage function that frees the Uint8 *pixels, and then
frees

the entire struct.

void freeImage( struct myImage *ptr )
{
myIMAGE_numOfImages–;
free( ptr->pixels );
free( ptr );
}

other images are successfully loaded, drawn, and freed in the exact
same manner. its only one image that causes the program to end when
it

tries to free its ptr->pixels. but i know its loaded successfully
because i can draw it to screen.

this problem is baffling me.

  • jeremiah

-----Original Message-----
From: Atrix Wolfe
To: sdl at libsdl.org
Sent: 2/1/2003 3:07 PM
Subject: Re: [SDL] free( ptr ) causes SDL Parachute Deployed?

just because the pointer isnt null that doesnt mean its a valid
memory

address. The pointer could be uninitialized, or something might be
changing its address to an address outside of the allowable address
range for your program. It could also be a problem of memory
corruption.

----- Original Message -----
From: Martell, Jeremiah < mailto:jmarte01 at bellarmine.edu
<mailto:jmarte01 at bellarmine.edu> >
To: ‘sdl at libsdl.org’ < mailto:‘sdl at libsdl.org
<mailto:‘sdl at libsdl.org’> >
Sent: Friday, January 31, 2003 11:37 PM
Subject: [SDL] free( ptr ) causes SDL Parachute Deployed?

hello,

my SDL app is ending with stderr.txt stating that SDL Parachute
has
been deployed. i have traced the reason to the line: “free( ptr );”.
ive
checked to make sure the ptr is not null, and it hasnt been freed
anywhere else before - and the malloc was successful. its always the
same pointer too, which is odd. if i comment out the "free( ptr );"
line
the program runs through to the end with no errors. what could be
causing a “free( ptr )” statement to mess up SDL?

  • jeremiah

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

Chris Thielen <@Christopher_Thielen>

If you’re running on an x86 Linux box, or at least can get
your program to run on one, I’d recommend valgrind. It’s
a gpl’d project that wraps a lot of common c functions,
including malloc and free and reports memory leaks,
invalid reads, and all that. It’s the perfect tool to track down
memory leaks when writing games and multimedia applications.

For Windows there are similar tools. I personally use the memory
manager that Paul Nettle published in his Ask Midnight column on
www.flipcode.com. Basically, you add one source file to your
project, recompile, and run your program. The memory manager writes
out one or more log files with information about memory that isn’t
freed properly. In addition, it will assert and jump into the
debugger whenever you do something invalid, such as overwriting
memory or freeing memory that isn’t yours. This free tool has
already saved me from many memory bugs; I couldn’t live without
it.

Read the article:
<http://www.flipcode.com/cgi-bin/msg.cgi?showThread=12September2000-
PresentingAMemoryManager&forum=askmid&id=-1>

And download the source code at:
ftp://ftp.flipcode.com/code/mmgr.zip
Matthijs Hollemans
www.allyoursoftware.com

one, I’d recommend valgrind. It’s a gpl’d project that wraps a lot of
common c functions, including malloc and free and reports memory leaks,
invalid reads, and all that. It’s the perfect tool to track down memory
leaks when writing games and multimedia applications.

Take a look at Memory Supervision System:
http://hem1.passagen.se/blizzar/mssOn Saturday 01 February 2003 11:21 pm, you wrote:

On Sat, 2003-02-01 at 22:03, Martell, Jeremiah wrote:

is there anyway to detect where this is happening? i guess i could go
through all my code and try and find out where, but that could be
pretty tedious. especially since all the code works and all the
images/fonts are loading and displaying correctly. is there any easy
way to find the problem, or at least narrow it down?

Disclaimer - I’m new to SDL and gcc, but have been programming in one
language or another for ages.

If you don’t want to try a new tool, try debugging the old way…

What happens if you try replacing one of your existing pngs with another?
Is it possible that the data in one of the png files itself is the issue?

Try just backing up both smile.png and smileyOLD.png, then…
copy smile.png TO smileyOLD.png - does this result in the same problem?
copy (original) smileyOLD.png to both (current) smileyOLD.png AND smile.png.
–same problem again?

Try, alternately, only handling ONE image at a time to see if it’s the png
file screwing things up.
eliminate all but one load() and one free() to try to narrow this.
After trying that with EACH image, start again, but this time do 2 at a
time.
Eventually you should pin it down.

If not, start adding couts (or printf()s) that tell you where you are, what
you’re doing, what variable/image/pointer you’re working on, what (memory)
size it should be, and how much data you’re trying to put there.

A lot of people seem to overlook the obvious when debugging, which is the
basic PRINT statement, adjusted for whatever the language-specific version
of that is. It’s the easiest and fastest way to do simple debugging. You
can usually save yourself a lot of time by slapping a few print statements
down in the general area of a problem.

HTH,
TomR.----- Original Message -----
From: Martell, Jeremiah
To: 'sdl at libsdl.org
Sent: Sunday, February 02, 2003 12:03 AM
Subject: RE: RE: [SDL] free( ptr ) causes SDL Parachute Deployed?

is there anyway to detect where this is happening? i guess i could go
through all my code and try and find out where, but that could be pretty
tedious. especially since all the code works and all the images/fonts are
loading and displaying correctly. is there any easy way to find the problem,
or at least narrow it down?

  • jeremiah