Error: ...value of ESP was not properly saved...

Started by
4 comments, last by Matias Goldberg 12 years, 3 months ago
(C++, Visual Studio 2010)

I get the following error when my app returns:

"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."

But only if two things are true:
1) You start the app outside of the IDE and then attach to it when it breaks.
2) You call a function implemented in a lib.

This code will reproduce the error:


int __stdcall
WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, char* lpCmdLine, int nCmdShow )
{
__debugbreak();
TestFn();

return 0;
}

(Code for lib not shown, but it would just implement 'TestFn()')

What's going on here?


edit:
Decided to show the code for the lib in case I'm doing that wrong:
test.h

bool TestFn( );


test.cpp


bool TestFn( )
{
return true;
}
Advertisement
This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention[/quote]Either:
1) TestFn contains code with a buffer-overrun/etc that is corrupting the stack.
2) ^^What the error says: a function was compiled with one calling convention, but was called using another convention.

If (2), it's probably caused by the lib having been compiled using different compiler settings than your program, so that your program and the lib both have a different idea of what the default convention should be.

[edit]What happens if you use CALLBACK instead of __stdcall on winmain?

No dice on using [font=helvetica, arial, verdana, tahoma, sans-serif][size=2][color=#282828]'[/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

CALLBACK'.[/font]



[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

It couldn't be (1) since the fn just returns true, and (2) would be strange since I created new projects for the test and used fully default settings.[/font]


(I of course switched it to compile the lib as a lib but that's all)



Remember, it only happens when you run the app outside the IDE and then break in when the __debugbreak hits. If I debug it from within the IDE it runs fine!



EDIT:



I think I tested similar code on another PC and it did not have the issue, prompting me to reinstall windows.

Still have the error however. Could somehow be something about my PC.
Just to update this, it IS something with my PC. The error will not happen on any other PC I try it on.

So it's some kind of hardware issue.
Are you overclocked? All manner of weird and seemingly impossible things can happen with overclocking... http://blogs.msdn.com/b/oldnewthing/archive/2005/04/12/407562.aspx

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This usually happens when you're using an old DLL while linking against a new lib & header that was modified.
Most likely one of the DLLs your app is using in your PC is different (newer or older) and that's why you get the error.

From what it looks like your VC Studio debug CRT DLLs are miss-matched (or your release DLLs, which are installed from a redist like this one). Try reinstalling Visual Studio.

This topic is closed to new replies.

Advertisement