Problem with scaling colliders

When I change properties (like halfExtents for box or radius for sphere) of collision component inside update function, it cause an error:
"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 “)”

Could you pls show us your project?

I created similar project at: https://playcanvas.com/editor/scene/602408.
The script is on the root. After 30-40 seconds the error is replicated.

It’s all because of Ammo.js.

Try to optimize your code - you change halfExtents 60 times per second, but it’s necessary only when camera’s position was changed.

This way you can reduce ammo.js memory usage, probably.

I guess @will knows better.

I think there is a bug. Looking at the engine source code, where changing the halfextents creates a new body in the simulation but doesn’t destroy the old one.

Edit: Scratch that, yes it does.

Edit Edit: Whoops… Didn’t see that you weren’t using rigidBodies, just collision components. I’m looking at the wrong of the engine code :sweat:

1 Like

It does not matter, sooner or later it crashes. And I make application that has to be runnig for hours. I made a test, and made something similar, but the script was changing halfExtents one entity per second and I leave it for one night. When I came back to work, it was already crashed.

So you’re saying that changing halfExtents causes crash, sooner or later, aren’t you?

Now that I’m looking at the right code:

When the halfExtents are changed, it calls initialize from trigger.js which removes the body from the simulation and then creates a new Ammo.btRigidBody without destroying the old one https://github.com/playcanvas/engine/blob/master/src/framework/components/collision/trigger.js#L28

I’m trying to think of a work around for the moment :confused:

Wondering if Trigger.destroy should also destroy the Ammo.btRigidBody as well.

So I’ve ‘fixed’ this here: https://playcanvas.com/editor/scene/602426

I’m not keen on this as we now adding and destroying multiple physics objects every frame.

There may be a better way to do this but it depends on what you are using the collision system for or was this an experiment?

Edit: Nope still crashing :frowning:

Correct, that’s what I’m saying.

Any news? I am also experiencing same issue

Do both of you need to have full physics or something to raycast against?

If the former, you would have to dig into the Ammo.js physics library to look at how to scale the collide using their local scale.