diff --git a/CHANGELOG.md b/CHANGELOG.md index 269c771..8cf757e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v3.9.1 +### Bug Fixes +* Fix crash when the avatar has a skinned mesh with out of bounds bone indices. [(more)](https://github.com/d4rkc0d3r/d4rkAvatarOptimizer/issues/129) + ## v3.9.0 ### Features * Generated shaders and materials are now stripped of all properties that got baked into the shader. diff --git a/Editor/d4rkAvatarOptimizer.cs b/Editor/d4rkAvatarOptimizer.cs index 46cb37d..d0b0917 100644 --- a/Editor/d4rkAvatarOptimizer.cs +++ b/Editor/d4rkAvatarOptimizer.cs @@ -2242,15 +2242,23 @@ void AddDependency(Transform t, Object obj) var meshBones = skinnedMesh.bones; var usedBoneIDs = new bool[meshBones.Length]; var boneWeights = skinnedMesh.sharedMesh.boneWeights; + int outOfRangeBoneCount = 0; + void MarkUsedBone(int boneIndex) { + if (boneIndex < 0 || boneIndex >= meshBones.Length) { + outOfRangeBoneCount++; + return; + } + usedBoneIDs[boneIndex] = true; + } for (int i = 0; i < boneWeights.Length; i++) { - usedBoneIDs[boneWeights[i].boneIndex0] = true; + MarkUsedBone(boneWeights[i].boneIndex0); if (boneWeights[i].weight1 > 0) { - usedBoneIDs[boneWeights[i].boneIndex1] = true; + MarkUsedBone(boneWeights[i].boneIndex1); if (boneWeights[i].weight2 > 0) { - usedBoneIDs[boneWeights[i].boneIndex2] = true; + MarkUsedBone(boneWeights[i].boneIndex2); if (boneWeights[i].weight3 > 0) { - usedBoneIDs[boneWeights[i].boneIndex3] = true; + MarkUsedBone(boneWeights[i].boneIndex3); } } } @@ -2262,6 +2270,10 @@ void AddDependency(Transform t, Object obj) AddDependency(meshBones[i], skinnedMesh); } } + if (outOfRangeBoneCount > 0) + { + Debug.LogWarning($"Skinned mesh renderer {GetPathToRoot(skinnedMesh)} has {outOfRangeBoneCount} out of range bone indices"); + } } foreach (var behavior in GetComponentsInChildren(true) .Where(b => b != null && (b.GetType().Name.Contains("Constraint") || b.GetType().FullName.StartsWithSimple("RootMotion.FinalIK")))) diff --git a/package.json b/package.json index 55fcf1d..2763294 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "d4rkpl4y3r.d4rkavataroptimizer", "displayName": "d4rkAvatarOptimizer", - "version": "3.9.0", + "version": "3.9.1", "unity": "2019.4", "description": "An optimizer aiming to reduce mesh & material count and more of VRChat 3.0 avatars.", "dependencies": {},