Advertisement

Crashes when using C++ objects

Started by April 05, 2016 05:13 PM
4 comments, last by Fbhywn 8 years, 7 months ago

Hello,

When creating or using C++ objects the application crashes in the function CallThisCallFunction.

I registered the interface like so:


engine->RegisterGlobalFunction("void RegisterGenerator(?&in)", asMETHOD(APIInterface, registerGenerator), asCALL_THISCALL_ASGLOBAL, &this);

engine->RegisterObjectType("World", 0, asOBJ_REF);
engine->RegisterObjectBehaviour("World", asBEHAVE_FACTORY, "World@ f()", asFUNCTION(WorldFactory), asCALL_CDECL);
engine->RegisterObjectBehaviour("World", asBEHAVE_ADDREF, "void f()", asMETHOD(World, addRef), asCALL_THISCALL);
engine->RegisterObjectBehaviour("World", asBEHAVE_RELEASE, "void f()",  asMETHOD(World, release), asCALL_THISCALL);
engine->RegisterObjectMethod("World", "void addBlock(Block@)", asMETHOD(World, addBlock), asCALL_THISCALL);

Whenever I call RegisterGenerator or addBlock it will crash at the end of CallThisCallFunction.

But this only happens on Windows tested with MinGW and MSVC, GCC under Linux is working fine.

Kind regards

It seems odd to me that you're passing &this as the global variable. Won't this point to an address on the stack?

Advertisement

Hi Fbhywn,

Use of '&this' (i.e. address of the this pointer) does indeed look odd. If you wanted to use the object pointer itself, you should simply use 'this' (i.e. address of the object).

However, I don't see a relationship between the crash in the call to RegisterGenerator and the call to addBlock. The cause is most likely different.

Can you show us the implementation of the mentioned methods and functions? Just from the way you've registered them it is not possible to know where the problem is.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I tried a little bit and it's not the method itself, i cleared the content of the registerGenerator method and removed all the other classes still crashes.

The signature of the method is:

void APIInterface::registerGenerator(asIScriptObject* generator)

This method is public and not static, also i replace the &this to this.

Could it has something to do that I store the engine in a pointer?

I made a small test project (which use cmake) and attached it.

?& in parameters require the use of a void* parameter, and an int for the type id, as stated here: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_var_type.html

Because you expect it to pass only an asIScriptObject* (which is probably the same size as a void*), it pushes too much onto the stack. This probably results in data corruption and an incorrect stack pointer when the method returns.

?& in parameters require the use of a void* parameter, and an int for the type id, as stated here: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_var_type.html

Because you expect it to pass only an asIScriptObject* (which is probably the same size as a void*), it pushes too much onto the stack. This probably results in data corruption and an incorrect stack pointer when the method returns.

Thanks this was the problem, I think I overlooked it.

This topic is closed to new replies.

Advertisement