Advertisement

Problem saving/loading bytecodes (angelscript bug?)

Started by May 19, 2007 04:11 PM
32 comments, last by WitchLord 17 years, 4 months ago
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
I haven't done any extensive testing on the save/load feature, so it's entirely possible that it is a bug in AngelScript itself. I'll have to make some tests with your example to see what I can find.

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

Advertisement
oh! Okey, it was driving me crazy!!

Well, I'll wait anxious to the next release! ;)

Thanks a lot for the answer and for the fantastic angelscript that i'm using in my games engine!


=====================================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
Sorry for taking so long about this, but the bug has finally been fixed. You can get the bug fix in revision 155 in the SVN.

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

Thank you very much! ;)
=====================================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
I'm still having problems when saving/loading bytecode. It works well but when i try to resize a script array, it crash with an unhandled exception. Here is the angelscript code i'm using:
const int COLLISION_MAX_ENTITIES = 200;class CheckCollision {	Actor@[] _list1;	Actor@[] _list2;	int _lastList1;	int _lastList2;	bool Initialize() {		_list1.resize(COLLISION_MAX_ENTITIES);		_list2.resize(COLLISION_MAX_ENTITIES);		_lastList1 = 0;		_lastList2 = 0;		return true;	}...}


The problem resides in the resizes. When I try to resize the arrays, it crashes with an unhandled exception in as_arrayobject.cpp method:

static void ArrayObjectResize(asUINT size, asCArrayObject *self){	self->Resize(size);}


If I try the same code without the preloaded bytecode, it works well.

Thanks!!!!

=====================================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
Advertisement
Seems to be some property of the script array types that isn't being properly restored. I'll investigate this. Thanks for reporting it.

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 forgot to mention that Actor is a script interface. I don't know if resizing arrays of C++ classes causes the same problem.
=====================================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
I'm unable to reproduce this last problem. I wrote the following test case:

static const char *script4 = "                          \n""const int COLLISION_MAX_ENTITIES = 200;                \n""interface Actor { void Test(); }                       \n""class CheckCollision {                                 \n""	Actor@[] _list1;                                \n""	Actor@[] _list2;                                \n""	int _lastList1;                                 \n""	int _lastList2;                                 \n""                                                       \n""	bool Initialize() {                             \n""		_list1.resize(COLLISION_MAX_ENTITIES);  \n""		_list2.resize(COLLISION_MAX_ENTITIES);  \n""		_lastList1 = 0;                         \n""		_lastList2 = 0;                         \n""		return true;                            \n""	}                                               \n""}";bool Test(){	int r;		// Compile and save the byte code 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);	engine->AddScriptSection(0, "script", script4, strlen(script4));	r = engine->Build(0);	if( r < 0 ) fail = true;	CBytecodeStream stream4;	engine->SaveByteCode(0, &stream4);	engine->Release();	// Load and execute the byte code	engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);	engine->LoadByteCode(0, &stream4);	r = engine->ExecuteString(0, "CheckCollision c; c.Initialize();");	if( r != asEXECUTION_FINISHED )		fail = true;	engine->Release();	return fail;}


The test passed without any problems.

Would you mind giving the above test a try on your target system to see if it reproduces your problem? I'll need your help to fix the problem. Without being able to reproduce the problem myself it can be next to impossible to fix.

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've ran your test and it works well...

I couldn't figure out what's going on with my code and I don't know how to show you without sending all of it (because it's big to be pasted in the forum).

What else could I try?


=====================================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

This topic is closed to new replies.

Advertisement