Skip to content

Commit

Permalink
fix: NRE if some bone is none
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Feb 1, 2023
1 parent d0f1ef2 commit 88efc2a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Editor/Processors/MergeBoneProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Process(OptimizerSession session)

foreach (var renderer in session.GetComponents<SkinnedMeshRenderer>())
{
if (renderer.bones.Any(mergeMapping.ContainsKey))
if (renderer.bones.Where(x => x).Any(mergeMapping.ContainsKey))
DoBoneMap(session, renderer, mergeMapping);
}

Expand All @@ -50,12 +50,12 @@ private void DoBoneMap(OptimizerSession session, SkinnedMeshRenderer renderer,
var oldBindposes = mesh.bindposes;
var boneMapping = new int[oldBones.Length];

var newBones = oldBones.Where(x => !mergeMapping.ContainsKey(x)).ToArray();
var newBones = oldBones.Where(x => !(x && mergeMapping.ContainsKey(x))).ToArray();
var newBindposes = new Matrix4x4[newBones.Length];

for (int i = 0, j = 0; i < oldBones.Length; i++)
{
if (mergeMapping.TryGetValue(oldBones[i], out var mapped))
if (oldBones[i] && mergeMapping.TryGetValue(oldBones[i], out var mapped))
{
var newIndex = Array.IndexOf(newBones, mapped);
if (newIndex == -1)
Expand Down

0 comments on commit 88efc2a

Please sign in to comment.