Hey Guys,
I'm evaluating angelscript for use in a project and have come across a problem. Btw, this could easily be my fault, so some insight would be appreciated.
I have a test structure defined in C and exposed to script. Pretty simple. I've provided ref count methods, a Construct function, etc.
If I create an instance of TestStruct in c, and pass into angel as an object handle, all is well. The following works beautifully, and all reference callbacks and return values are working.
// Script
int SuperFunc( TestStruct@ weird )
{
int i = weird.DoTest1( 12 );
int j = i;
return j;
}
So DoTest1 calls back to C with a proper "this" pointer.
However, if I declare an instance of TestStruct within script, and attempt to call any methods on it, I end up with a garbage "this" pointer.
The first line properly calls back to my Construct function in C and a newly allocated instance is returned back to angel. On the following line, when angel calls DoTest1, it's pushing a different address onto the stack than was returned from Construct. Somewhere internally, the object pointer got stomped.
// Script
void Crashes()
{
TestStruct s;
s.DoTest1( 5 );
}
Any thoughts? Any help is greatly appreciated... thanks in advance.
Here's my registration for TestStruct.
// C
pEngine->RegisterObjectType("TestStruct", sizeof(TTestStruct), asOBJ_CLASS_CDA);
pEngine->RegisterObjectBehaviour("TestStruct", asBEHAVE_CONSTRUCT, "void f()",asFUNCTION(TTestStruct::Construct), asCALL_CDECL_OBJLAST);
pEngine->RegisterObjectBehaviour("TestStruct", asBEHAVE_ADDREF,"void f()",asMETHOD(asCScriptString,AddRef), asCALL_THISCALL);
pEngine->RegisterObjectBehaviour("TestStruct", asBEHAVE_RELEASE,"void f()",asMETHOD(asCScriptString,Release), asCALL_THISCALL);
pEngine->RegisterObjectBehaviour("TestStruct", asBEHAVE_ASSIGNMENT,"TestStruct &f(const string ∈)", asMETHOD(TTestStruct, operator =,
(const TString&), TTestStruct&),asCALL_THISCALL);
pEngine->RegisterObjectBehaviour("TestStruct", asBEHAVE_ASSIGNMENT,"TestStruct &f(const TestStruct ∈)", asMETHOD(TTestStruct, operator=,
(const TTestStruct&), TTestStruct&),asCALL_THISCALL);
pEngine->RegisterObjectMethod( "TestStruct", "int DoTest1( int i )", asMETHOD(TTestStruct,DoTest1), asCALL_THISCALL );
[Edited by - delscorcho on February 2, 2007 1:23:55 AM]