Hi there!
I'm trying to save/load to/from bytecode file. But if i use arrays in the script, the application crashes with an access violation when loading the binary file:
// NEXT: Must go through the bytecode and set the correct objecttype pointer where used
int asCRestore::Restore()
{
// Before starting the load, make sure that
// any existing resources have been freed
module->Reset();
unsigned long i, count;
asCScriptFunction* func;
asCProperty* prop;
asCString *cstr;
// structTypes[]
READ_NUM(count);
module->classTypes.Allocate(count, 0);
for( i = 0; i < count; ++i )
{
asCObjectType *ot = NEW(asCObjectType)(engine);
ReadObjectTypeDeclaration(ot);
engine->classTypes.PushLast(ot);
module->classTypes.PushLast(ot);
ot->refCount++;
}
// usedTypes[]
READ_NUM(count);
module->usedTypes.Allocate(count, 0);
for( i = 0; i < count; ++i )
{
asCObjectType *ot = ReadObjectType();
module->usedTypes.PushLast(ot);
ot->refCount++;
}
.
.
.
}
In the last line (ot->refCount++) ot is NULL, so there i have the access violation.
Here's the script i've used:
Sprite spr;
float[] f(5);
bool Initialize() {
if (!spr.Load("data/graphics/roxy.spr"))
return false;
spr.SetFrame(10);
spr.SetPos(20,20);
return true;
}
void Update(float dt) {
spr.Update(dt);
}
void Draw() {
spr.Draw();
}
If I comment the float[] f(5); line, the problem dissapear.
Is it something i'm doing wrong when registering the arrays?
Here is how I registered the floats array:
if (ScriptMgr::RegisterObjectType("float[]", sizeof(vector<float>), asOBJ_CLASS_CDA) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour("float[]", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(ConstructFloatArray, (vector<float> *), void), asCALL_CDECL_OBJLAST) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour("float[]", asBEHAVE_CONSTRUCT, "void f(int)", asFUNCTIONPR(ConstructFloatArray, (int, vector<float> *), void), asCALL_CDECL_OBJLAST) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour("float[]", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructFloatArray), asCALL_CDECL_OBJLAST) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour("float[]", asBEHAVE_ASSIGNMENT, "float[] &f(float[]∈)", asMETHODPR(vector<float>, operator=, (const std::vector<float> &), vector<float>&), asCALL_THISCALL) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour("float[]", asBEHAVE_INDEX, "float &f(int)", asMETHODPR(vector<float>, operator[], (vector<float>::size_type), float &), asCALL_THISCALL) < 0)
return false;
if (ScriptMgr::RegisterObjectMethod("float[]", "int length()", asMETHOD(vector<float>, size), asCALL_THISCALL) < 0)
return false;
Thanks a lot!
=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8