Advertisement

Problem saving/loading bytecodes (angelscript bug?)

Started by May 19, 2007 04:11 PM
32 comments, last by WitchLord 17 years, 7 months ago
You say the code crashes inside the array resize. Do you know if the resize is called from Initialize() or maybe it is called at another moment when there are already some elements in it? In other word does your problem only happen inside CheckCollision.Initialize() or in other locations of your scripts as well? Does it always happen at the same moment, or is it only sometimes?

Would it be possible to try to narrow down the location of the problem by commenting out half of your script, then test again? Continue with that recursively until you've identified the problematic components.

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

It happens always. If I comment the resize lines in initialize, i have another crash in:
int asSGCObject::AddRef(){	// TODO: Must be made atomic	// Increase counter and clear flag set by GC	refCount = (refCount & 0x7FFFFFFF) + 1;	return refCount;}


The line that through the error is:
        if (!_ship.Initialize())	    return false;


But it crashes before executing any line in the Initialize method. Here is the declarations:

#include "constants.as"#include "globals.as"#include "ship.as"const int GAME_STATE_NONE		     = 0;const int GAME_STATE_EXIT		     = 1;const int GAME_STATE_NEXTLEVEL	 = 2;class InGame {	Ship		_ship;	int			_state;	bool Initialize(int level) {		_state = GAME_STATE_NONE;		_asteroidsCount = 0;	  Log("Initialize InGame CheckCollision...");		if (!g_checkCollision.Initialize())			return false;	  Log("Initialize InGame Ship...");		if (!_ship.Initialize())			return false;		if (!g_AsteroidMgr.Initialize(level))			return false;		return true;	}...}const int SHOTS_COUNT			      = 10;const float SHIP_ANIM_FPS		    = 15.0f;const float SHIP_ROT_SPEED		  = 0.2f;const float SHIP_MAXSPEED		    = 0.4f;const float SHIP_ACCEL			    = 0.0003f;const int SHIP_STATE_NONE		    = 0;const int SHIP_STATE_INVISIBLE	= 1;const int SHIP_STATE_EXPLODING	= 2;const float INVISIBLE_TIME      = 2000.0f;class Ship : Actor {	float _accumTime;	float _angle;	float _vx;	float _vy;	int _lastShot;	int _lives;	int _state;	float _invisibleTime;	uint _currentColor;	Sprite		_sprite;	Sprite		_sprExplosion;	Animation	_aniExplosion;	Shot@[]		_shots;	string GetName() {		return _sprite.GetName();	}	float GetPosX() { return _sprite.GetPosX(); }	float GetPosY() { return _sprite.GetPosY(); }	float GetCollisionRadius() { return _sprite.GetCollisionRadius(); }	bool GetCheckCollision() { return _sprite.GetCheckCollision(); }	bool Initialize() {    Log("Initialize");		if (!_sprite.Load("data/graphics/uridium.spr")) {			return false;		}		if (!_sprExplosion.Load("data/graphics/explosion.spr"))			return false;		if (!_aniExplosion.Load("data/graphics/explosionNave.ani"))			return false;    Log("Shots resize");		_shots.resize(SHOTS_COUNT);    Log("Shots intialize");		for (int i=0; i < SHOTS_COUNT; i++) {			Shot shot;			@_shots = @shot;			if (!_shots.Initialize())				return false;		}		Reset();....}


I don't know what's going on here. :(
=====================================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
Witchlord, you should run that test as two separate apps. It's possible for some error to slip through because some improperly loaded bit of code refers to deleted memory that just happens to still hold correct data.
You may be right, Deyja. I'll give that a try.

I'm however more inclined to think it has something to do with object type conflicts inside the engine, maybe a combination of script classes and registered classes. In my small test the conflict doesn't appear, but with the larger script from mckracken there may be problems while registering the objects.

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

By adding more complexity to the script I was able to reproduce the problem.

It happens with the following script:

interface Actor {  }InGame g_inGame; class InGame{	Ship _ship;	bool Initialize(int level)	{		if (!_ship.Initialize())			return false;		return true; 	}}class Ship : Actor{	bool Initialize()	{		return true;	}}


and engine->ExecuteString(0, "g_inGame.Initialize(0);")

If I remove the Actor interface the problem doesn't happen anymore. Which may be a good lead to the cause of the problem.

Now that I've reproduced it, it shouldn't be long before I have it fixed. Hopefully it is the last of the bugs that have been bothering.

While trying to reproduce your problem I also stumbled upon another bug that I need to fix. This one is an assert failure in the script compiler after trying to recover from a compile errors. It shouldn't be too difficult to fix either.

I'll let you know as I have more information.

Regards,
Andreas

[Edited by - WitchLord on June 21, 2007 4:22:40 PM]

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 discovered the problem. There is a design problem with the asCRestore class. It is currently not able to load script class declarations that are out of order. In the test the structure declarations are stored in the order: Actor, InGame, Ship, which is alright. But when the file is loaded again, the InGame structure is referencing a type that has not yet been registered in the engine (Ship). Because of that the _ship property is not properly initialized (the object type is set to null).

A work around for this problem is to make sure the script classes are declared in the right order. In the test the Ship class declaration must be moved up above the InGame class. Of course, if you have circular referencing of types, then there really is no work around.

I'll have this problem fixed as soon as possible.

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
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've fixed the problem now. You can get the solution from the SVN (rev 159).

Let me know if there are more problems with the bytecode serialization. There likely is as my unit tests for this part are really weak and uncomplete so far, but hopefully everything that you need should work perfectly.

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

It solved the problem but i have another yet. Now it brings me an error in:
int asSGCObject::Release(){	// TODO: Must be made atomic	// Decrease counter and clear flag set by GC	refCount = (refCount & 0x7FFFFFFF) - 1;	if( refCount == 0 )	{		CONV2GCCLASS(this)->Destruct();		return 0;	}	return refCount;}


in line "refCount = (refCount & 0x7FFFFFFF) - 1;" when I try this:

_shots.resize(SHOTS_COUNT);for (int i=0; i < SHOTS_COUNT; i++) {	Shot shot;	@_shots = @shot;	if (!_shots.Initialize())		return false;}


If you need more info, let me know.

[EDIT]
I forgot to mention that the error occurs in "Shot shot;" line.
[/EDIT]
=====================================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
You must be the first to truly use this save/load feature to its fullest. I can't believe this many problems would have gone unnoticed unless it was a feature that was never really used.

Unfortunately it is a feature where it is very difficult to predict the tests that are necessary to do a thurough code coverage, so it is bound to have more problems. But, if you'll be patient with me I promise I'll fix every last one of them as they are discovered.

Thanks for keeping the reports coming in.

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

This topic is closed to new replies.

Advertisement