Meshes with skeletons that have needInitialSkinMatrix=true crash when cloned

I finally got the chance to look into a bug I have seen since upgrading from babylonjs 5 beta 4 to the latest rc versions.

It seems that meshes with a skeleton that has needInitialSkinMatrix = true crash when cloned.

This seems to happen now because the Mesh constructor assigns the cloned mesh’s skeleton to the new clone by default and it didn’t do this previously (I’d actually like this to be optional, but that’s a separate matter).

This means that AbstractMesh.getPositionData is now called whereas it was not previously.

The line var skeletonMatrices = this.skeleton.getTransformMatrices(this); returns undefined as skeleton.prepare() does not calculate skeleton._transformMatrices if skeleton.needInitialSkinMatrix = true.

So AbstractMesh.getPositionData crashes when Matrix.FromFloat32ArrayToRefScaled is called as the passed in skeletonMatrices is undefined.

Hope this makes sense… its very late here.

Playground example of the crash (please open the debugger)


1 Like

@bghgary will look into it ASAP :slight_smile:

I have a local fix, but I’m wondering why you want to set needInitialSkinMatrix = true. How does this help you?

PR: Fix exception when cloning a skinned mesh with skeleton.needInitialSkinMatrix is true by bghgary · Pull Request #12132 · BabylonJS/Babylon.js · GitHub

1 Like

Hi @bghgary,
The mesh in question was exported from maya as a .Babylon file and when it is imported needInitialSkinMatrix is set to true.
Until I hit this bug, I didn’t even know the variable existed.
I was able to work around the bug by setting it to false as soon as the mesh is loaded but I wanted to flag the bug regardless as other people may hit it and not realise what’s happening.
Thanks for working on the fix :+1:

Ok, that’s odd that the exporter is doing this. @Guillaume_Pelletier FYI.

Do not now why… this is set explicitly

            BabylonSkeleton babylonSkeleton = new BabylonSkeleton
                id = skinIndex,
                name = name,
                bones = ExportBones(skin),
                needInitialSkinMatrix = true

Do you want me to remove it ???

I think so. I don’t see any good reason why it is set. Can you try and see if anything breaks?