Hello Alan,
Thursday, January 5, 2006, 10:38:59 PM, you wrote:
AW> What i like to do is make a function that i pass text to. The function
AW> opens a file, writes the text, then closes the file (thus saving the file
AW> changes, very important because if it crashes before you close the file, you
AW> may be missing text from the log that should be there, which makes it
AW> useless).
AW> In my code, when im having crashing or preformance problems etc like this, i
AW> make it output stuff to the log file in various places in the code.
AW> Then, I run the program and when it’s done (i killed it, it crashed,
AW> whatever) i look at the log file and see what the last thing it said was.
AW> If i need more info, i put more output between the last thing it reported
AW> and the next thing it should have reported and i keep going in finer and
AW> finer detail until i find the line of code causing all the problems.
AW> Works really good for me (:
Heh, maybe you won’t belive me but I got exactly same idea and did same thing
and that’s how I found where my code is crushing.
But!
I wrote here that I found the bug, but later, even “fixed” that bug appeared again.
I got one array where I hold pointers of loaded images:
SDL_Surface** bobs; //images
And I’m allocating array mem like:
bobs= new SDL_Surface* [number_of_bobs];
And for number_of_bobs I always put bigger number that I really got images to
load. I.e. I got 217 images and I put 400. 1 KB of memory more or less - who
cares.
So, I found that in my loading function:
int MG_BOBS::Load (char* name)
{
SDL_Surface* tmpsrf=NULL;
bobs[first_free]=IMG_Load(name);
if (bobs[first_free])
{
SDL_SetAlpha(bobs[first_free], SDL_SRCALPHA | SDL_RLEACCEL , 255);
tmpsrf=SDL_DisplayFormatAlpha (bobs[first_free]);
if (tmpsrf)
{
SDL_FreeSurface(bobs[first_free]);
bobs[first_free]=tmpsrf;
}
first_free++;
return first_free-1;
}
return -1;
}
… func call IMG_Load() crushes. First I didn’t checked how many pictures I
actually got so I increased number_of_bobs to 1000, program stopped crushing
and I realized - it must be it. But later just in case i checked how many bobs
I’m really loading(217 so far), so I saw it wasn’t it. I also saw that random array size
gives me random results - sometime it crushes and sometime not. All this in
fullscreen mode only - windowed it never (or very rarely) crush.
And crush was always in libpng1.dll
I checked on Internet for that lib and saw that some versions crush with alpha
channel (which I use), but mine (1.0.8.0) is not mentioned. For testing I
removed part of image loading function which converts formats:
int MG_BOBS::Load (char* name)
{
SDL_Surface* tmpsrf=NULL;
bobs[first_free]=IMG_Load(name);
if (bobs[first_free])
{
first_free++;
return first_free-1;
}
return -1;
}
And THIS works. I expected that my bobs/images (ex Amiga user) will have white
background instead of transparent, but that didn’t happen ?!? Only my frame rate
dropped from 41 to 37 fps. But it works!
So, it must be that part of code I removed is messing up unallocated memory and
the more unused memory I alloc the better chance for that code part is to hit
right there.
At end, is this my bug? Or lib is bugged? If so, which version should I use?
Is this format conversion really needed (I can live without that extra 4 fps)?–
Best regards,
Milan mailto:milan_g at eunet.yu