Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Out of memory

fantasy
Registered User
Quote
2016-02-26 17:12:57

In my test level (Windows, physics on) I have added various things to the standard behaviours, like multiple stand/idle, attack, hit and die animations. At first look everything works fine.

But - depending on the number of NPCs/enemies - after 18 to 50 minutes the game crashes down to 1 - 3 frames per second and I get a lot of "out of memory" errors in my scripts.

An example with 2 fishes, who swim around and flee, if the player comes too close let's the game crash after around 50 minutes. Besides "Game Actor with Health" (randomly patrol) and "Collide when moved" the fishes have the following script:

[code]// The following embedded xml is for the editor and describes how the behavior can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action

/*
<behavior jsname="behavior_wlEntityMoveNoGravNoKill" description="Entity no gravitation no kill">
<property name="WalkAnimation" type="string" default="walk" />
<property name="RunAnimation" type="string" default="run" />
<property name="DieAnimation" type="string" default="die" />
<property name="Fly" type="bool" default="false" />
<property name="EscapeDistance" type="int" default="40" />
<property name="WalkSpeed" type="int" default="7" />
<property name="RunSpeed" type="int" default="20" />
</behavior>
*/

behavior_wlEntityMoveNoGravNoKill = function()
{
this.LastTime = null;
this.InitHeight = null;
this.MyPos = null;
this.Animation = null;
this.MyName = null;
this.MyVariable = null;
this.SpeedName = null;
};

// called every frame.
// 'node' is the scene node where this behavior is attached to.
// 'timeMs' the current time in milliseconds of the scene.
// Returns 'true' if something changed, and 'false' if not.
behavior_wlEntityMoveNoGravNoKill.prototype.onAnimate = function(node, timeMs)
{
// get the time since the last frame
if (this.LastTime == null)
{
// we were never called before, so store the time and cancel
this.LastTime = timeMs;
this.InitHeight = ccbGetSceneNodeProperty(node, 'Position');
this.MyName = ccbGetSceneNodeProperty(node, 'Name');
this.Animation = ccbGetSceneNodeProperty(node, 'Animation');
this.MyVariable ="vx"+this.MyName;
this.SpeedName = ""+this.MyName+".movementspeed";
return false;
}
//ccbSetCopperCubeVariable(name, -1);

this.MyPos = ccbGetSceneNodeProperty(node, 'Position');
var player = ccbGetSceneNodeFromName("Player1");
var playerpos = ccbGetSceneNodeProperty(player, 'Position');
//calculate distance
var dx = playerpos.x - this.MyPos.x;
var dy = playerpos.y - this.MyPos.y;
var dz = playerpos.z - this.MyPos.z;
var dist = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2) + Math.pow(dz, 2));

this.Animation = ccbGetSceneNodeProperty(node, 'Animation');
//walk and escape
if ((dist > this.EscapeDistance + 5) && this.Animation != this.WalkAnimation && this.Animation != this.DieAnimation)
{
ccbSetCopperCubeVariable(this.SpeedName, this.WalkSpeed);
ccbSetSceneNodeProperty(node, "Animation", "None");
ccbSetSceneNodeProperty(node, "Animation", this.WalkAnimation); //ccbPlaySound("ding1.wav");
}
if (dist < this.EscapeDistance && this.Animation != this.RunAnimation && this.Animation != this.DieAnimation)
{
ccbSetCopperCubeVariable(this.SpeedName, this.RunSpeed);
ccbSetSceneNodeProperty(node, "Animation", "None");
ccbSetSceneNodeProperty(node, "Animation", this.RunAnimation);
}

//Correct Y-position
if (!this.Fly)
{
/*
if (this.MyPos.y > waterlevel - 3 && dist > this.EscapeDistanc


fantasy
Registered User
Quote
2016-02-26 17:14:42

I don't know, what's wrong with this script and let's the game crash, but I must admit that I don't know much about scripting. I have just taken some actions and behaviours from the extensions folder and changed and expanded them to my needs.


fantasy
Registered User
Quote
2016-02-26 17:17:34

I have just seen, that not the whole code was posted, so here is the rest:

	//Correct Y-position
if (!this.Fly)
{
/*
if (this.MyPos.y > waterlevel - 3 && dist > this.EscapeDistance)
{
this.MyPos.y -= 0.1;
ccbSetSceneNodeProperty(node, "Position", this.MyPos);
}
*/
if (this.MyPos.y > this.InitHeight.y + 1 && dist > this.EscapeDistance)
{
//ccbPlaySound("ding1.wav");
this.MyPos.y -= 0.01;
ccbSetSceneNodeProperty(node, "Position", this.MyPos);
}
if (this.MyPos.y < this.InitHeight.y - 1 && dist > this.EscapeDistance)
{
this.MyPos.y += 0.01;
ccbSetSceneNodeProperty(node, "Position", this.MyPos);
}
}

return true;
}



niko
Moderator
Quote
2016-02-27 10:56:51

Hm, difficult to say with only this partial code, sounds like you have a memory leak somewhere in your javascript.

If you like, send me the file (see support -> contact) and I'll have a look at that.


fantasy
Registered User
Quote
2016-02-27 19:44:48

Thanks Niko, I have sent you an email.


fantasy
Registered User
Quote
2016-02-27 20:01:11

I just wanted to add that I like Coppercube and am quite happy, what I could achieve in my first test level - if we can solve this memory leak:

🔎︎



aimingBullets
Guest
Quote
2016-02-28 06:44:38

Wow... your game is looking good dude... keep it up...!


leo
Guest
Quote
2016-07-24 10:41:12

it is easy to import from an external 3d software, hands with weapons like in your picture?


fantasy
Registered User
Quote
2016-09-15 23:34:45

Hi Leo,

Yes, it was easy to import 3D-models like the hands, but I still don't know how to get rid of the memory leak :(


niko
Moderator
Quote
2016-09-16 05:50:24

As I wrote per mail, I looked through your game, and it seems to be some javascript object which isn't freed by your scripts. You probably add some objects into a global variable and over time, they get more and more and are never freeed. You have so many and long scripts in there, of which I didn't quite understand which script does what, so that it probably easier for you to spot this. But if you like I can try to look again.


fantasy
Registered User
Quote
2016-09-20 01:11:02

Looks like I missed your email, maybe it got in my spam folder?


niko
Moderator
Quote
2016-09-20 04:57:03

Yes, could be, seems like during the last months for example gmail tends to think my mails are spam, although I'm only usually writing a few lines without any web links and similar...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact