Strange Access Violation Error!

Hi. I was wondering if someone could help me out, because I’m utterly baffled.

I created a class for Animated Surfaces. It basically just contiains a tiled
surface, and methods for drawing only a certain tile. Multiple calls (on the
order of 10-15…the specific call that does it changes each time) to its
constructor eventually produce an error “Unhandled exception at 0x77f52f9c in
ATC Game.exe: 0xC0000005: Access violation reading location 0x0091a2ad”

I checked 0x0091a2ad in memory,and it’s completely blank.

If I turn on the Debug heap in memory, it runs fine in the debugger, but crashes
in Explorer (Access violation 0xC0000005 in NTDLL.DLL).

The code for the constructor is:

SDL_AnimSurface(char *filename,short unsigned int Frame_W,short unsigned int
Frame_H,short unsigned int Frame_Count)
{
TColor = 0;
temp = 0;
GFX = SDL_LoadBMP(filename);
Frame_Width = Frame_W;
Frame_Height = Frame_H;
Number_of_Frames = Frame_Count;

	TColor = SDL_MapRGB(GFX->format,255, 255, 255);
      temp = SDL_SetColorKey(GFX, SDL_SRCCOLORKEY, TColor);
	if (temp < 0)
	{
			fprintf(stderr, "Init Transparency failed :", SDL_GetError());
	};
};

Using breakpoints, it seems to happen inside the “SDL_SetColorKey()” function…
before that line, all my variables (temp, GFX, TColor, SDL_SRCCOLORKEY) are
fine. While inside it, it crashes, and the debugger shows all my variables as
garbage.

Any help would be mucho appreciated.

perhaps GFX is NULL because SDL_LoadVMP failed. You never check whether the file loads.

-LIM-

Jonathan Atkins <jcatki jonatkins.org> writes:

perhaps GFX is NULL because SDL_LoadVMP failed. You never check whether the
file loads.

-LIM-

Thank you.

You’re right, and I should fix that (I’ll do that right now actually, while I’m
thinking of it).

But, I’ve checked it in the debugger at a breakpoint, and GFX isn’t NULL going
into the function.

TrentonZero <TrentonZero yahoo.com> writes:

Jonathan Atkins <jcatki jonatkins.org> writes:

perhaps GFX is NULL because SDL_LoadVMP failed. You never check whether the
file loads.

-LIM-

Thank you.

You’re right, and I should fix that (I’ll do that right now actually, while
I’m
thinking of it).

But, I’ve checked it in the debugger at a breakpoint, and GFX isn’t NULL going
into the function.

This is the strangest thing I’ve ever seen.

I added a quick little peice of code to check if GFX is NULL. Understand, it
doesn’t throw exceptions or anything…just a quick printf to stderr saying “GFX
is NULL”.

And it works like a charm. No error happens, nothing gets printing to stderr, no
access violations.

I don’t understand how that alone would fix it, but it did, so…umm…thanks.

TrentonZero wrote:

TrentonZero <TrentonZero yahoo.com> writes:

Jonathan Atkins <jcatki jonatkins.org> writes:

perhaps GFX is NULL because SDL_LoadVMP failed. You never check whether the

file loads.

-LIM-

Thank you.

You’re right, and I should fix that (I’ll do that right now actually, while

I’m

thinking of it).

But, I’ve checked it in the debugger at a breakpoint, and GFX isn’t NULL going
into the function.

This is the strangest thing I’ve ever seen.

I added a quick little peice of code to check if GFX is NULL. Understand, it
doesn’t throw exceptions or anything…just a quick printf to stderr saying “GFX
is NULL”.

And it works like a charm. No error happens, nothing gets printing to stderr, no
access violations.

I don’t understand how that alone would fix it, but it did, so…umm…thanks.

don’t forget that on windows stderr is redirected to a file called stderr.txt
the same goes for stdout.txt

-LIM-

It very likely didn’t fix anything. Adding debug code and having the symptoms
"disappear" is usually indicative of pointer problems. Look over your code
carefully and try to spot anywhere a pointer might be uninitialized or
otherwise corrupted.

JeffOn Sunday 03 October 2004 06:54 pm, TrentonZero wrote:

This is the strangest thing I’ve ever seen.

I added a quick little peice of code to check if GFX is NULL. Understand,
it doesn’t throw exceptions or anything…just a quick printf to stderr
saying “GFX is NULL”.

And it works like a charm. No error happens, nothing gets printing to
stderr, no access violations.

I don’t understand how that alone would fix it, but it did,
so…umm…thanks.

Jeff <j_post pacbell.net> writes:

It very likely didn’t fix anything. Adding debug code and having the symptoms
"disappear" is usually indicative of pointer problems.

You’re right. The error came back.

I went through all of my pointers with a fine tooth comb, and found a string
pointer that was being corrupted (in a completely different area of the program,
which is why I never found it before). Replaced it with a regular character
array and now there are no more errors.

Thanks everyone for your time and help!