MVC++ Debug Error

Started by
4 comments, last by CTar 18 years, 8 months ago
Hey, can anyone explain this error to me please and give any ideas what might be causing it, program complies fine but get this debug error during execution: "The Value of ESP was not properly saved accros a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a differnt calling convention" re-read it a few times and cant get my head round what its trying to say, any help..? [Edited by - neiluk on August 3, 2005 12:25:22 PM]
Advertisement
Quote:Original post by neiluk
"The Value of ESP was not properly saved accros a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a differnt calling convention"


... clear as mud!

What it's saying is basicly that the stack pointer somehow got corrupted are you doing some nasty function pointer cast perhaps?

This is a bit VC++ specific but similar switches exist for other compilers.
If you have a function declared with (for example) __stdcall (somtimes writteh CALLBACK in when writing windows code) and then foricbly assign that to a normal function pointer (that defaults to __cdecl) then you'll end up with the called function clearing the stack and the calling code later trying to do the same thing . Triggering the runtime check, the same is true the other way around and for other combinations of calling conventions.

So my guess is that you're using a C-style cast to assign to a function pointer and then doing an indirect call.

HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
found the guilty line of code but still dont see whats wrong with it, although im rubbish with pointers so its probably my fault .

void Enemy ::Update(float dt, ExplosionList *explosions){		if(health <= 0)	{		DEAD = TRUE;		explosions->addNode(Explosion(position)); // <-- The Dodgy line	}	else	{		oldPosition = position;		position = position + (velocity * dt);	}}


Where explosions is a pointer to a linked list declared in the main source file. Not sure if thats enough code to figure out the problem from, but any suggestions to fix it?
help anyone....?
That error is more than likely misleading. It can mean a mistake in calling convention but more often than not it means you've overwritten a stack variable and the stack clean up code in debug mode runs through each variable and checks its padding to make sure it wasn't written to.

In your case its because your tyring to add a stack node to your list. Change it to a heap allocation. After you exit the funciton it tries to delete teh explosion you added to the linked list.

ie explosions->addNode( new Explosion(position));
Cheers
Chris
CheersChris
What is "Explosion", a function or a function pointer? Also what does it returns? The problem sounds to have something to do with the calling convention, I dont know much about calling conventions, but when you create a function pointer like this:

void (*fp)();


It's probably seen as this by the compiler:

void __cdecl (*fp)()


Then if you do like this:

void __stdcall Func(){}int main(){fp = Func();}


Then fp will point to a function with another calling convention, which will cause an error like the one you are having. The error will probably be thrown when you actually try to call the function like this: "fp()"

Even though you dont think you are using calling conventions, you might, macros like WINAPI and CALLBACK can change the calling convention.

EDIT: Didn't think about Explosion being a class, then it might be something like what collida1 said.

This topic is closed to new replies.

Advertisement