asBEHAVE_RELEASE couldn't register with a virtual function!

Started by
2 comments, last by loboWu 15 years, 10 months ago
in C++ class CBase { public: CBase(){} virtual ~CBase() {} int a; virtual void AddRef() {} virtual void Release() {} }; class CMytype: public CBase { public: CMyType(); virtual ~CMyType(); virtual void Release() {} }; CMytype global; CMytype* GetMytype() { return &global } and In AS, register it with a type { r = engine->RegisterObjectType("Mytype", 0, asOBJ_REF); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Mytype", asBEHAVE_ADDREF, "void f()", asMETHOD(CMytype, AddRef), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Mytype", asBEHAVE_RELEASE, "void f()", asMETHOD(CMytype, Release), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectProperty("Mytype", "int a", offsetof(CMytype, a)); assert( r >= 0 ); r = engine->RegisterGlobalFunction("Mytype @GetMytype()", asFUNCTION(GetMytype), asCALL_CDECL); assert( r >= 0 ); } and I use also register the "any" type and write a sample script { Mytype @test = @GetMytype(); any anytest; antest.store(test); } //after running script, it will call test->Release() to release the object, //but it will raise an exception! But if I change the virtual Release() to non virtual, it is OK! Am I wrong? or it is just a bug? Maybe I need to change asCALL_THISCALL to another flag, but I am a little confuse about asCALL_THISCALL, asCALL_CDECL. Thanks.
Advertisement
This has the looks of a bug in AngelScript. I'll investigate this.

Regards,
Andreas

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 wasn't able to reproduce the problem that you reported. Either the problem has already been fixed, or the code you gave isn't enough to reproduce it.

I noticed that the code you gave have some minor errors in it that makes it fail to compile. It's nothing big but it's obviously not the same code that you had when encountering the problem. Could you give me another piece of code that compiles and reproduces the problem?

---

You're registering the Mytype correctly, and AngelScript fully supports virtual methods.

The problem is probably not with the virtual call itself, but rather that the object pointer is invalid for some reason. If the object pointer is invalid a virtual method would fail because the virtual function table would also be invalid. A non-virtual method would succeed though (unless it tries to access a member of the object).

As to your doubt about asCALL_THISCALL and asCALL_CDECL. For class methods you should use asCALL_THISCALL, and for global functions you should use asCALL_CDECL. AngelScript will give an error if you do it incorrectly, so don't worry about it too much.

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

Thansk!

I will retry with 2.13.0 !

This topic is closed to new replies.

Advertisement