Error...probably due to memory overflow

uncaught exception: abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 67108864, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which adjusts the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ") at jsStackTrace@https://code.playcanvas.com/ammo.dcab07b.js:7:15014
stackTrace@https://code.playcanvas.com/ammo.dcab07b.js:7:15185
abort@https://code.playcanvas.com/ammo.dcab07b.js:23:191516
abortOnCannotGrowMemory@https://code.playcanvas.com/ammo.dcab07b.js:7:16035
enlargeMemory@https://code.playcanvas.com/ammo.dcab07b.js:7:16480
ho@https://code.playcanvas.com/ammo.dcab07b.js:16:1
jc@https://code.playcanvas.com/ammo.dcab07b.js:14:1
sd@https://code.playcanvas.com/ammo.dcab07b.js:13:1
_c@https://code.playcanvas.com/ammo.dcab07b.js:13:1
ad@https://code.playcanvas.com/ammo.dcab07b.js:13:1
Ke@https://code.playcanvas.com/ammo.dcab07b.js:12:1
$o@https://code.playcanvas.com/ammo.dcab07b.js:16:1
btBvhTriangleMeshShape@https://code.playcanvas.com/ammo.dcab07b.js:23:415882
createPhysicalShape@https://code.playcanvas.com/playcanvas-stable.dbg.js:26177:28
doRecreatePhysicalShape@https://code.playcanvas.com/playcanvas-stable.dbg.js:26235:20
onSetModel@https://code.playcanvas.com/playcanvas-stable.dbg.js:25871:7
fire@https://code.playcanvas.com/playcanvas-stable.dbg.js:608:5
Component/<@https://code.playcanvas.com/playcanvas-stable.dbg.js:21167:7
fire@https://code.playcanvas.com/playcanvas-stable.dbg.js:608:5
set@https://code.playcanvas.com/playcanvas-stable.dbg.js:21179:9
changeTerrain@https://launch.playcanvas.com/api/files/code/352037/directory/terrain.js:175:13
fastRoute@https://launch.playcanvas.com/api/files/code/352037/directory/Nerastus.js:358:17
update@https://launch.playcanvas.com/api/files/code/352037/directory/Nerastus.js:50:21
_updateInstances@https://code.playcanvas.com/playcanvas-stable.dbg.js:23661:9
onUpdate@https://code.playcanvas.com/playcanvas-stable.dbg.js:23665:5
fire@https://code.playcanvas.com/playcanvas-stable.dbg.js:608:5
update@https://code.playcanvas.com/playcanvas-stable.dbg.js:21104:7
update@https://code.playcanvas.com/playcanvas-stable.dbg.js:20659:5
makeTick/<@https://code.playcanvas.com/playcanvas-stable.dbg.js:21004:7

If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

1 Like

I guess it’s a memory problem due to the use of destroy function that seems to not clear the memory creating garbage but don’t know how to solve that

It’s a bit weird that it’s happening in ammo.js. What code is triggering this error?

That’s a good question, i can tell you how to replicate it: https://playcanvas.com/editor/scene/396696 launch the game from editor, the M key open the map, travel to Rekdar or Foren, travel back to Leas’ Bones and again to Rekdar or Foren and you will get that error i think the terrain.js is where the error is triggered, that’s where i put the code to generate towns and where the unnecessary entities are destroyed.

Your project is getting to a point where it’s very hard for an outside person to debug easily.

I recommend trying to narrow down what is causing that bug to occur by commenting chunks of code and think through the possibilities.

Eg:

  • Does it happen when you don’t destroy entities?
  • Does it happen if you only destroy one entity?
  • Is it one particular entity or one particular group of entities causing this?

It’s very hard to debug for me too :smiley: the only reference i can use is the terrain.js 175:13 that point this

            this.entity.removeComponent('collision');
            this.entity.model.model = model;
            this.entity.addComponent('collision', {
                type: 'mesh'
            });     // <-----line 175
            this.entity.collision.model = collisionModel;

Yes the problem is due for sure when re-creating the phisical shape of terrain maybe i’m missing something to erase the memory?

Check the memory profile in Chrome Dev tools.

Part of me is wondering if you are using too much memory by creating the collision model each time you enter and return to the town? Perhaps the it isn’t being destroyed properly in Ammo?

Is the terrain destroyed when you exit each area?

Nope isn’t destroyed, this is the code when enter each area

changeTerrain: function() {
            var house=app.root.findByTag('house');
            for(var x=0;x<house.length;x++) {
                
                house[x].destroy();
            }
            this.lM=app.root.findByName('Player').script.player.localMap;
            var img = app.assets.get(this.heightMap[this.lM]).resource.getSource();
            var model = this.createTerrainFromHeightMap(img);
            var collisionModel = this.createTerrainFromHeightMap(img, this.subdivisions / 2);
            var buildings = app.assets.get(this.dbTowns).resource;
            
            var oggdata = this.parseTownData(buildings);
            this.entity.removeComponent('model');
            this.entity.model=null;
            this.entity.addComponent('model', {
                type: 'asset'
            });
            //this.entity.model.castShadows=true;
            this.entity.removeComponent('rigidbody');
            this.entity.rigidbody=null;
            this.entity.addComponent('rigidbody', {
                type: 'static'
            });
            this.entity.rigidbody.friction=1;

            this.entity.removeComponent('collision');
            this.entity.collision=null;
            this.entity.model.model = model;
            this.entity.addComponent('collision', {
                type: 'mesh'
            });
            this.entity.collision.model = collisionModel;
            
            this.placeBuildings();
        },

I get the feeling that when you remove the rigidbody, you don’t actually delete the collision mesh from the physics world but without really checking the engine code, I’m not 100% sure.

I recommend looking at the engine code and potentially ammo.js to see what options you have from removing a rigidbody from the world.

Can’t find anything useful ;_;

It’s totally a memory overflow trouble, i changed a bit the code in terrain.js and the line where the error show up is changed.