Sorry to stalk you on this forum!
If i don’t use my game for a couple seconds a get this errors. Is that normal?
In the console:
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
In the game:
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 Error
at jsStackTrace ( https://code.playcanvas.com/ammo.dcab07b.js:7:15014)
at stackTrace ( https://code.playcanvas.com/ammo.dcab07b.js:7:15185)
at abort ( https://code.playcanvas.com/ammo.dcab07b.js:23:191516)
at abortOnCannotGrowMemory ( https://code.playcanvas.com/ammo.dcab07b.js:7:16035)
at enlargeMemory ( https://code.playcanvas.com/ammo.dcab07b.js:7:16480)
at ho ( https://code.playcanvas.com/ammo.dcab07b.js:16:90614)
at jc ( https://code.playcanvas.com/ammo.dcab07b.js:14:24638)
at ji ( https://code.playcanvas.com/ammo.dcab07b.js:11:182188)
at new btRigidBody ( https://code.playcanvas.com/ammo.dcab07b.js:23:290616)
at RigidBodyComponent.createBody ( https://code.playcanvas.com/playcanvas-stable.dbg.js:31179:18)
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.
April 12, 2020, 2:21pm
Looks like you have exhausted the 64MB heap memory allocated to the physics engine (ammo.js). Take care to ensure that you are allocating rigid bodies correctly/efficiently.
What are you meaning with this?
It is a pity that colliders always need a rigidbody to be effected by raycasts or another collider.
April 12, 2020, 2:37pm
I mean that you should check that everything you are creating is genuinely needed. For example:
Are you creating bodies unnecessarily? For unreachable parts of your level, for example.
Are you creating mesh-based collision which is unnecessarily highly detailed?
Are you dynamically allocating bodies at run-time and never freeing them?
…or something else I haven’t considered.
Oke, i will recheck everything.
Is it true that colliders always need a rigidbody to be effected by raycasts or another collider?
April 12, 2020, 2:51pm
Yes, raycasts are performed by the
The underlying physics engine ammo.js require the presence of a rigid body to perform the raycast.
The only time you don’t need a rigid body (and just have a collision component) is when you create a trigger volume:
I build my level with blocks so i can easily redesign the level. But every block need a static rigidbody. Do you think that can be the problem?
The most other entities has a kinematic rigidbody and are moved by script.
April 12, 2020, 3:19pm
Could be. How many blocks/bodies are we talking about here?
Currently about 100 blocks, 7 characters, and some other objects with a ridigbody.
April 12, 2020, 3:41pm
So about 110-120 bodies? That’s fine. Is each block a mesh collider? How many triangles per block?
These are the settings of my blocks:
April 12, 2020, 6:52pm
So you’re saying you have about 100 of those box colliders? That’s definitely not enough to exceed the engine’s 64MB memory pool for physics. Something else must be going on. Have you changed anything in your project that triggered this?
No not that has to do with the points you mentioned. From the beginning I always got the message [object_event] error if the browser was inactive for too long, but I think that’s normal.
I just published a new version. Maybe you see something that could be the cause.
April 12, 2020, 9:46pm
Check out this project:
That creates 37 x 37 box bodies (in a script). So that’s 1369 bodies. Beyond that, ammo.js runs out of memory. So if you are creating more than that, yeah, the error is reasonable.
I wonder if it’s possible to set
Module.TOTAL_MEMORY early enough to set a larger heap size as suggested in the error message.
@slimbuck might have some thoughts on that.
But having played your game, I fundamentally don’t believe it should be utilizing all the physics memory. Do you create all of the rigid bodies + colliders in code or in the Editor hierarchy panel?
I have made a script that allows me to clone the entities from a prefab, so that I only have to make changes in one entity. The entities in the editor are removed after cloning at the start of the game.
April 12, 2020, 10:56pm
If you want to print how many rigidbody and collision components are in your scene, put this in the update function of a script:
But whichever script you use, make sure there’s only one instance of it in the scene.
numBodies = 220
numCollision = 224
If I am the only one with this problem there will be something wrong in my project. I still plan to start all over again if I have a good foundation.
I’ve definitely worked in scenes with way more rigid bodies (and complex ones, like terrains meshes) with no issue.
Yes so something else must be the cause.
Is the error [object_Event] normal if you don’t use the launch tab for a while?