Havok: crash in raycast worldRegion.floatingOrigin

Hi everyone,

Sorry, no playground. I have seen this crash the first time now. In a game, during enemy turn, lots of raycasts fired within a frame. Cannot reproduce :frowning:

Crash happens here: Babylon.js/packages/dev/core/src/Physics/v2/Plugins/havokPlugin.ts at 7ddc62e2ee59b2f034db81c73e04f3804cbc7222 · BabylonJS/Babylon.js · GitHub

// Extract:
public raycast(from: Vector3, to: Vector3, result: PhysicsRaycastResult | Array<PhysicsRaycastResult>, query?: IRaycastQuery): void
//(...)
const worldRegion = query?.ignoreBody?._pluginData?.worldRegion ?? this._worldRegions[0];
const offset = worldRegion.floatingOrigin;

I do not use the query parameter so I would think the crash is caused by this._worldRegions[0]. I swear I do not touch _worldRegions. I do not even know what this feature is.

Are there some indirections through which I could accicentally clear the array?

Best wishes
Joe

cc @Cedric

I’m taking a look!

Please test this branch to see if it fixes properly your use case Fix world region crash by CedricGuillemet · Pull Request #18705 · BabylonJS/Babylon.js · GitHub

Cross-linking probably cause for future reference: Havok HP_World_GetNumBodies returns N-1 instead of N