Jump to content
  • Advertisement
Sign in to follow this  
Fbhywn

Crashes when using C++ objects

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Edited by Fbhywn

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites

?& 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.

Share this post


Link to post
Share on other sites

?& 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!