• 15
• 15
• 11
• 9
• 10

# MessageCallback with asCALL_THISCALL

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

## Recommended Posts

Hi again, my stuff runs again now after the update, except that this seems to be a problem (only in debug, running fine in release):
m_engine->SetMessageCallback(asMETHOD(ScriptEngine, messageCallback), this, asCALL_THISCALL);
This is the error message I get: 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. Any ideas? Thanks.

##### Share on other sites
Is your messageCallback a static method of the ScriptEngine? If it is then you need to register it with asCALL_CDECL instead of asCALL_THISCALL. If that is not the problem, then please show us the ScriptEngine::messageCallback function signature so that we can verify if it is correct (parameters, return type, etc).

Regards,
Andreas

##### Share on other sites
It is a non-static method:
//.hclass ScriptEngine {//...        asIScriptEngine *m_engine;public://...	void messageCallback(const asSMessageInfo *msg, void *param);};//.cpp//...m_engine->SetMessageCallback(asMETHOD(ScriptEngine, messageCallback), this, asCALL_THISCALL);

Works fine in release but not in debug.

##### Share on other sites
When the message callback is implemented as a class method it shouldn't have a second parameter. Only the asSMessageInfo pointer. This is why you get the stack corruption.

See: http://www.angelcode.com/angelscript/sdk/docs/manual/classas_i_script_engine.html#74192fe950808eb72a64e3e371f0ea02

Regards,
Andreas