Skip to content

Commit

Permalink
Merge pull request #749 from anatawa12/nre-in-merge-bone
Browse files Browse the repository at this point in the history
NRE in merge bone
  • Loading branch information
anatawa12 authored Nov 25, 2023
2 parents b393348 + 69d9714 commit af20d08
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- Error if there are null in ingore transforms of PhysBone `#749`

### Security

Expand Down
2 changes: 2 additions & 0 deletions Editor/Processors/MergeBoneProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ protected override void Execute(BuildContext context)

internal static void MapIgnoreTransforms(VRCPhysBoneBase physBone)
{
if (physBone.ignoreTransforms == null) return;
var ignoreTransforms = new HashSet<Transform>();

var processQueue = new Queue<Transform>(physBone.ignoreTransforms);
while (processQueue.Count != 0)
{
var transform = processQueue.Dequeue();
if (transform == null) continue;
if (!transform.gameObject.GetComponent<MergeBone>())
{
ignoreTransforms.Add(transform);
Expand Down
37 changes: 36 additions & 1 deletion Test~/MergeBoneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ExtremeSmall()
}

[Test]
public void IgnoreTransformOfPb()
public void IgnoreTransformOfPhysBone()
{
var root = TestUtils.NewAvatar();
var pbRoot = Utils.NewGameObject("merged", root.transform);
Expand All @@ -55,5 +55,40 @@ public void IgnoreTransformOfPb()
Assert.That(physBone.ignoreTransforms,
Is.EquivalentTo(new[] { nonMergedIgnored.transform, mergedChild.transform }));
}

[Test]
public void NullElementsInIgnoreTransformInPhysBone()
{
var root = TestUtils.NewAvatar();
var destoryed = Utils.NewGameObject("destoryed", root.transform);
var pbRoot = Utils.NewGameObject("merged", root.transform);
var child = Utils.NewGameObject("child", pbRoot.transform);
var mergedIgnored = Utils.NewGameObject("mergedIgnored", child.transform);
var mergedChild = Utils.NewGameObject("mergedChild", mergedIgnored.transform);

var nonMergedIgnored = Utils.NewGameObject("nonMergedIgnored", child.transform);

mergedIgnored.AddComponent<MergeBone>();

var physBone = pbRoot.AddComponent<VRCPhysBone>();

physBone.ignoreTransforms.Add(mergedIgnored.transform);
physBone.ignoreTransforms.Add(nonMergedIgnored.transform);
physBone.ignoreTransforms.Add(destoryed.transform);
physBone.ignoreTransforms.Add(null);
Object.DestroyImmediate(destoryed);

MergeBoneProcessor.MapIgnoreTransforms(physBone);
}

[Test]
public void NullIgnoreTransformListInPhysBone()
{
var root = TestUtils.NewAvatar();
var pbRoot = Utils.NewGameObject("merged", root.transform);
var physBone = pbRoot.AddComponent<VRCPhysBone>();
physBone.ignoreTransforms = null;
MergeBoneProcessor.MapIgnoreTransforms(physBone);
}
}
}

0 comments on commit af20d08

Please sign in to comment.