Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Custom script goes out of memory!

just_in_case
Moderator
Quote
2021-09-19 11:08:46

After playing the game for a decent amount of time all the custom scripts in my game are going out of memory.

the game starts with 155 MB of ram usage and the ram usage increases up to 300MB, just because of the script. and then it throws errors out of memory for all the custom scripts used in my game.

there is no loading of textures or anything, only some do later thing and changing of animation and setting and getting of variables going on.

No for loops or any other loops, just a few if and else statements and some increments of variables going on.

If anybody else has encountered out of memory error and knows how to fix this then please let me know.

everything works fine for a decent amount of time but then games start lagging and then eventually goes into a memory error.

@Niko If you know what causes this error and if you have any suggestions to get rid of these errors.

I think this is something related to previously encountered bugs that are hard to reproduce. where the game crashes or freezes after playing for some time.
This same issue of freezing of game has been noticed in @smnmhmdy's game "CODENAME: Drop".
where you play the game for some time and then the FPS starts dropping and eventually freeze the game.

hope somebody has a solution to this.


just_in_case
Moderator
Quote
2021-09-19 13:14:45

just realized that it shows the line number as well that is going out of memory.

and I found that ccbGetCopperCubeVariable and ccbgetSceneNodeProperty commands are getting assigned to variables on those lines. inside the prototype of behavior OnAnimate. I will try to look into this if I will be able to sort out this by myself.


just_in_case
Moderator
Quote
2021-09-19 16:21:13

After fiddling a lot I finally managed to fix one behavior to not go out of memory. But that's strange only thing I did was creating new variables with same code and setting new variables as value for old variables.

But this is again not working with all the script, I tried doing the same that fixed the error in another behavior but it is not helping at all.

It seems there is memory leak within the engine and if that's really the case then this will ruin everything.

I have 3 custom scripts in my game and they all are giving me out of memory error at the same time.

And the line that the console windows shows for the error has code that gets a variable onAnimate function, I also tried putting my code into a frameEvent instead of the onAnimate function but still having the same out of memory error.

@Niko should look into this.


count2rfeit
Registered User
Quote
2021-09-19 18:34:48

I would remember CC was intended to be able to build games WITHOUT coding... and It does. When you add scripts and make things complicated - you are going beyond what CC was designed to do. Niko can not really fix what is not really broken....

Well, just my thoughts about CC. When I was building games with it, I did my best to figure out how to use it as is - to create the look and feel of the game I wanted without having to add extra scripts (or at least a minimum amount). And I managed to do some pretty cool things with CC as what Niko created it to be. And the games worked as intended.

Maybe you should rethink and use less complicated means to create your game? Having a finished working game is what everyone should hope to achieve...

Again, just my thoughts....


just_in_case
Moderator
Quote
2021-09-19 20:42:08

I don't know why you are thinking that I am creating some complicated stuff, Coppercube is meant to support coding. and all I am doing us using some if and else statement and coppercube variables and counters.

I myself has written many scripts for this engine, so I have experience with coding as well. And the above script uses nothing special then some variables and if and else statement.
This isn't the first time I encountered this issue. I did had a chat with @niko with a similar issue when I posted helix jump demo. That demo was having the same issue. But unfortunately i was not able to reproduce the issue.
This might be due to a corrupted project or with something else. I am not talking about something that is not broken.

And I am not the only one that has encountered this thing.
@tim12345 , @smnmhmdy has also faced the same issue with their projects as well, there might be others as well of whom I am not aware about.

I am just hoping that this is something related to my script. Not an engine memory leak.

For me and for many others out there it will be hard to create games without using custom extensions or scripts.

There is a huge javascript api library in the documentation that has more content than any other documentation stuff.

So I strongly beleive that custom scripting is a necessary part of this engine. That helps in making this engine a no coding engine.

The only thing is that, inbuilt actions and behaviors are written in C++ and while the custom scripts and extension uses a javascript interpreter.

I admire your work and your skills, your fantasy level design was awesome with reshade and without reshade as well. Creating 3D levels and design, no doubt doesn't require custom scripts, but I am personally not a person who can rely on to the default behaviors and scripts for the gameplay that's why I try to create and provide custom scripts to the community to help the people out here.

Even the project that is giving me out of memory error is in development to be shared with the community.

I rarely do a personal project. Most of the time I work on projects to provide to the community.

Anyways thanks for your feedback 😇😇 I appreciate your comment😇 but I am still hoping for a reply from @Niko's side. Meanwhile i will be trying to find any issue in my code.


just_in_case
Moderator
Quote
2021-09-20 07:44:05

So, I am finally able to fix the issue. This is not related to custom scripts, but if your game goes out of memory or if there is any memory leakage then the debug console will only throw errors for custom scripts.

the issue was caused by every few seconds do something behavior. Don't use 1ms as a value there if you are getting the error. or try to avoid the use of this behavior if you encounter such an issue. where your game runs good enough for some time but after playing for a good time it starts lagging and then freezes or crashes, then checks if your scene has every few seconds do something behavior attached and if you are calculating things at 1ms or something like that. Remove the behavior and out of memory will be fixed.

even if you put 100ms, or 1000ms as the value in there, it will crash your game it will take a much longer time to crash but will eventually freeze or crash.

but this doesn't happen always, that is why the bug is unreproducible. This can happen due to some glitch, or some sort of corruption in your project. the reason why this happens is unknown.

So whenever you guys encounter such an issue, always check for every few seconds do something behavior.

hope this info will be helpful to others, I am glad that I was able to fix my issue.


VP
Guest
Quote
2021-09-20 09:19:28

I figured other people would experience this eventually.

I've noticed major problems with "every few seconds" and "do something later" and "on first draw". Also "Rotate object" causes memory leak problems for me.

It's extremely difficult to figure out why - sometimes it works,sometimes it doesn't.

Most fixes we've found so far:

1- some of the default scripts (from the coppercube site) still have errors which need to be commented out.

2- You can use variables to control the flow of events when using "every few seconds" and "on first draw".

3- Increase all "rotate speed" actions and increase "every few seconds" intervals.

4- Swap out any fbx static/animated models and replace them with .dae and .x models instead.

5-Any models with "every few seconds" or "rotate" events - change them to an "animated static model" (instead of just a "static model"). Coppercube then seems to calculate the attached events differently.

All these things have helped to fix the problems I was encountering...... Memory leaks which gradually slowed the game to a crash, glitch animations, single events which somehow repeated over and over and over again (movements, sounds, variables etc.), rotating items which got stuck/slow, AI problems etc etc.


VP
Guest
Quote
2021-09-20 09:32:40

...also, using "animate scale" can cause problems for the "every few seconds" instruction - unless you comment out one of the buggy lines of code in the "animate scale" script.

That was a fix which sorted quite a few nightmare problems I was having.


just_in_case
Moderator
Quote
2021-09-21 06:14:03

@VP yeah, thanks for pointing out these things. I was quite frustrated and was thinking it has to do something with my scripts but it was the inbuilt behavior that was causing the memory leak. It seems that the use of do-later with every few seconds should be avoided completely.


VP
Guest
Quote
2021-09-21 09:41:15

Yes, agreed.

It's sad because they're very useful actions but they definitely do seem to cause problems sometimes. Hopefully it's something that can be fixed in future updates.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Int?rnational" (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