[SOLVED] Vehicle Physics issue when delay enabling

Hello

image

I have mainmenu ui…
When i click on play button i disable mainmenu ui and enable the car and road entity.

Expected this output to come…
image

But this car stuck (looks like no tire rigidbody - no movement) and errors as follows:
image

unhandled exception while calling "update" for "vehicle" script:  RuntimeError: memory access out of bounds
    at https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.wasm?id=37771509&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=a6819ea71a53e67f1dfe3e42957c2971:wasm-function[175]:0xb3ad
    at https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.wasm?id=37771509&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=a6819ea71a53e67f1dfe3e42957c2971:wasm-function[336]:0x1ac4a
    at yn (https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.wasm?id=37771509&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=a6819ea71a53e67f1dfe3e42957c2971:wasm-function[1025]:0x4499e)
    at b._emscripten_bind_btRaycastVehicle_updateWheelTransform_2 (https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.js?id=37771553&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=6b7ab3989e4f9f17c86e44380f9181c6:276:70)
    at R.updateWheelTransform (https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.js?id=37771553&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=6b7ab3989e4f9f17c86e44380f9181c6:663:128)
    at scriptType.Vehicle.update (https://launch.playcanvas.com/api/assets/files/Scripts/vehicleScript/vehicle.js?id=37771518&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6:154:21)
    at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:43756:19)
    at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:43792:11)
    at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:44260:49)
    at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:44272:9)
_scriptMethod @ playcanvas-stable.dbg.js:43760
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:49882
launch.js:8000 RuntimeError: memory access out of bounds
    at https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.wasm?id=37771509&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=a6819ea71a53e67f1dfe3e42957c2971:wasm-function[175]:0xb3ad
    at https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.wasm?id=37771509&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=a6819ea71a53e67f1dfe3e42957c2971:wasm-function[336]:0x1ac4a
    at yn (https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.wasm?id=37771509&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=a6819ea71a53e67f1dfe3e42957c2971:wasm-function[1025]:0x4499e)
    at b._emscripten_bind_btRaycastVehicle_updateWheelTransform_2 (https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.js?id=37771553&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=6b7ab3989e4f9f17c86e44380f9181c6:276:70)
    at R.updateWheelTransform (https://launch.playcanvas.com/api/assets/files/Ammo/ammo.wasm.js?id=37771553&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6&t=6b7ab3989e4f9f17c86e44380f9181c6:663:128)
    at scriptType.Vehicle.update (https://launch.playcanvas.com/api/assets/files/Scripts/vehicleScript/vehicle.js?id=37771518&branchId=626e8937-3262-4bec-a31d-bdcc366e04f6:154:21)
    at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:43756:19)
    at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:43792:11)
    at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:44260:49)
    at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-stable.dbg.js:44272:9)

How i can solve this issue?

Thanks

1 Like

Have you made any changes in vehicle updates? It shows a memory leak issue. Also, the car stuck issue is of dynamic rigid body of tires that are not placed in it’s right place.
Try resolving the memory leak issues first and if possible add the project link so that one can see what can be the issue.

For collider issue, find Debug_Draw variable in vehicle script and make its value ‘true’ and then you can actually see the dynamic rigid body position properly.

1 Like

I though something is wrong with my vehicle script…

so I tried same thing on official project directly.
https://developer.playcanvas.com/en/tutorials/vehicle-physics/

image
And got a same result…

To prevent leaking issue i try putting check for entity enabled… but it does not help…

Edit:
I try this…
image
Vehicle wheel > debug render

(here output with auto enabled car)
image

(here output with manually enabled car - stuck)
image

1 Like

what exactly are you changing in the vehicle script? Because if you are just making changes in UI then it won’t effect the vehicle physics.

Ok,
Let me explain with official project so it will be easy to understand what i did…
https://developer.playcanvas.com/en/tutorials/vehicle-physics/

:arrow_forward: So i disabled following things
image

:arrow_forward: Then i started game …
Output: Empty road on screen without car…

:arrow_forward: Then i enabled this
image
Output: car and road visible but car is stuck…(end up with memory leak error)

It’s hard to say what the cause is exactly, something about the way the wheels are initialized and reference the car body or something. In any case, you can fix it by creating a new empty entity called “Car” and parenting the active “Car Graphics” and “Car Physics” to this new entity and then disabling and enabling the parent “Car” entity instead.

image

Hope that helps!

3 Likes

@ChandlerTwins I am sorry to say but it is still giving me same error…

I tried as u said
image

What should i do?

@ChandlerTwins was on the right track, if we make vehicle script component do it’s initialisation on the postInitialize step (after the wheels), it works.

I’ve updated the tutorial/sample project now.

2 Likes
Vehicle.prototype.postInitialize = function () {
    ...
};

Yes, it working now…

@saif, @ChandlerTwins, @yaustar
Thanks all for help. :slightly_smiling_face: :+1:

2 Likes