cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

Bullet Physics: memory access out of bounds

Open GeTechG opened this issue 7 months ago • 7 comments

Cocos Creator version

3.8.5

System information

Windows 11

Issue description

There is a complete freeze of the engine and a bunch of errors at random times, and I could not understand the specific reasons, from my observations the bug is observed when there is a new collision with something, conditionally the player goes into the trigger. Also I used in the project Configurable constraint, PointToPointConstraint maybe it will help.

Relevant error log output

Uncaught RuntimeError: memory access out of bounds
    at 001ca272:0x19291
    at 001ca272:0x36c8c
    at 001ca272:0x3875b
    at 001ca272:0x38964
    at 001ca272:0x68e46
    at 001ca272:0x65ab9
    at Object.DynamicsWorld_stepSimulation (bullet.release.wasm.js:10:32466)
    at BulletWorld.step (bullet-world.ts:196:12)
    at PhysicsSystem.postUpdate (physics-system.ts:367:39)
    at Director.tick (director.ts:791:38)

Steps to reproduce

Complex scene with many colliders, Configurable constraint, PointToPointConstraint. Take the ball, throw it into the trigger, and then walk around the trigger, it may not work right away, you need to turn around sharply and crash in, you may need to restart a few times.

https://github.com/user-attachments/assets/471fb5da-6733-4710-91de-04614cf65d7e

Minimal reproduction project

test_PHYS_BUG.zip

GeTechG avatar Apr 14 '25 12:04 GeTechG

Hi @GeTechG , could you try to provide a demo for reproducing the issue? Otherwise, according the exception stack, it's difficult to figure out. Thanks.

dumganhar avatar Apr 14 '25 14:04 dumganhar

Hi @GeTechG , could you try to provide a demo for reproducing the issue? Otherwise, according the exception stack, it's difficult to figure out. Thanks.

I'll try to recreate a little later, last attempt didn't go well, since this bug I found in a commercial project I can't provide you with.

GeTechG avatar Apr 14 '25 15:04 GeTechG

@dumganhar I made a minmal project, please take a look.

GeTechG avatar Apr 15 '25 14:04 GeTechG

Great, I will try to figure out.

dumganhar avatar Apr 20 '25 23:04 dumganhar

I would like to clarify that I found the source of the problem, the problem occurs after deleting a node with physics, as I understand there is an unsynchronization of the physics engine and cocos, because of which there is a reference to non-existent memory, I temporarily solved the problem by hiding objects instead of deleting actually so I realized that the problem is in the deletion.

GeTechG avatar Apr 21 '25 07:04 GeTechG

That's a good catch. Recently, I don't have enough time to investigate this issue. Sorry about that it may be delayed.

dumganhar avatar Apr 25 '25 07:04 dumganhar

@GeTechG Please refer to the modifications in this PR and remove the redundant PointToPointConstraint for the small node in the test cases.

bofeng-song avatar May 28 '25 02:05 bofeng-song