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?
-----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:
-
load “alpha.png” image (font)
-
load “alpha2.png” image (font)
-
load “test.png” image.
-
load “smiley.png” image.
-
load “smileyOLD.png” image
-
main loop, draw all three images to screen, and also two strings
with each font.
-
free all fonts
-
free “test.png”
-
free “smiley.png”
-
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?
-----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.
-----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?
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>