[SOLVED] Unknown ammo error

Hello, someone of you know what this error means?

Hi @ayrin,

Check the following post, it may be the same cause:

yes @Leonidas seems the same, but in my case is due to consecutive loading when changing town, so i don’t know how to solve it.

Out of my head I’d say in that case your issue may be you are loading the new content (models/bodies etc) before you have unloaded the previous one.

So out some point you go over the limit of memory available to Ammo.js

yes guess so since the terrain get generated every time i change town for the buildings i just re-allocate them

@Leonidas really each time i generate the terrain i use removeComponent to delete model, rigidbody and collision component, i set also each component to null, but seems it isn’t enough to avoid that error

Hmm, if you remove the rigidbody and collision components, then the engine will also remove them from the Ammo physics world. The problem you have indeed is caused by Ammo running out of memory. Something somewhere is created, but not removed, before being created again.

Terrain.prototype.changeTerrain= function() {
            // disable all the houses
            var house=this.app.root.findByTag('house1');
            for(var x=0;x<house.length;x++) {
                house[x].enabled=false;
            }
            house=this.app.root.findByTag('house2');
            for(var x=0;x<house.length;x++) {
                house[x].enabled=false;
            }
            house=this.app.root.findByTag('house3');
            for(var x=0;x<house.length;x++) {
                house[x].enabled=false;
            }
            // get the localMap value
            this.lM=this.app.root.findByName('Player').script.player.localMap;
            var img =this.heightMap[this.lM].resource.getSource();;
            var model = this.createTerrainFromHeightMap(img, this.subdivisions);
            var collisionModel = this.createTerrainFromHeightMap(img, this.subdivisions / 2);
            //var buildings =this.app.assets.get(this.dbTowns).resource;
            this.entity.enabled=false;
            //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.entity.enabled=true;
            this.placeBuildings();
        };

I’m pretty sure there are dragons in this.createTerrainFromHeightMap(). How many polygons does the resulting mesh have? And how do you handle its lifecycle?

It might be a good idea to create a new project with just the terrain generator to try to isolate the issue.

We could probably test the performance with physics in it too

Ok no prob i will create a test project brb

added you both to project, sorry i wanted to make the button work to change terrain but seems i’m missing something. lM should increase to change the heightmap. I have put just 1 terrain type.

Fixed the button, i don’t see any issue with ammo, can you check?
https://playcanvas.com/editor/scene/974717

Found out a bug in the buildings replacement, they were multiplied, solved the issue. Thanks a lot.

2 Likes