# Function call run-time error

This topic is 4688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have two functions: GUIElement *GetActiveElement(); GUIElement *FindElement(string); Both are registered with AngelScript. GetActiveElement() works, but FindElement does not. Windows gives me this error:
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 convention.

Could it be the string that is causing the error? I have included the scriptstring from the sample, and called RegisterScriptString(). If you need to know any more please just tell me.

##### Share on other sites
Does FindElement() expect a std::string by value? This would explain why ESP is wrong, since the library is pushing a asCScriptString on the stack, but FindElement() only removes a std::string.

Actually you cannot pass ScriptString to a function by value since it will not correctly handle the reference counting if that is so (the destructor is even protected to prevent C++ from instantiating the class locally). In fact, I may have to change the library to check for this case, as it is a configuration error.

Instead you ought to pass the string by reference, and register FindElement() with the following declaration "GUIElement@ FindElement(string &in)".

If this isn't the error, then you might want to verify the calling convention you specified when registering the function: asCALL_CDECL or asCALL_STDCALL.

Regards,
Andreas

##### Share on other sites
I was passing the strings by value [dead]
I changed it to pass by reference and it works now. Thanks a lot for the help.