From 11b10a82d5423852805bb9e2f8771f2c190bef5f Mon Sep 17 00:00:00 2001 From: bd_ Date: Mon, 25 Sep 2023 22:58:02 +0900 Subject: [PATCH] fix: NPEs resulting from bones being deleted under armature lock (#448) Fixes: #447 --- .../Runtime/ArmatureAwase/BidirectionalArmatureLock.cs | 6 ++++++ .../Runtime/ArmatureAwase/OnewayArmatureLock.cs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/Packages/nadena.dev.modular-avatar/Runtime/ArmatureAwase/BidirectionalArmatureLock.cs b/Packages/nadena.dev.modular-avatar/Runtime/ArmatureAwase/BidirectionalArmatureLock.cs index 889216f8..8c4eb6c4 100644 --- a/Packages/nadena.dev.modular-avatar/Runtime/ArmatureAwase/BidirectionalArmatureLock.cs +++ b/Packages/nadena.dev.modular-avatar/Runtime/ArmatureAwase/BidirectionalArmatureLock.cs @@ -169,6 +169,12 @@ namespace nadena.dev.modular_avatar.core.armature_lock // Check parents haven't changed for (int i = 0; i < _baseBones.Length; i++) { + if (_baseBones[i] == null || _mergeBones[i] == null || _baseParentBones[i] == null || + _mergeParentBones[i] == null) + { + return false; + } + if (_baseBones[i].parent != _baseParentBones[i] || _mergeBones[i].parent != _mergeParentBones[i]) { return false; diff --git a/Packages/nadena.dev.modular-avatar/Runtime/ArmatureAwase/OnewayArmatureLock.cs b/Packages/nadena.dev.modular-avatar/Runtime/ArmatureAwase/OnewayArmatureLock.cs index cc26f80e..f263f54f 100644 --- a/Packages/nadena.dev.modular-avatar/Runtime/ArmatureAwase/OnewayArmatureLock.cs +++ b/Packages/nadena.dev.modular-avatar/Runtime/ArmatureAwase/OnewayArmatureLock.cs @@ -174,6 +174,8 @@ namespace nadena.dev.modular_avatar.core.armature_lock handle = default; if (_disposed) return false; + LastOp.Complete(); + _fault.Value = 0; _wroteAny.Value = 0; @@ -199,6 +201,12 @@ namespace nadena.dev.modular_avatar.core.armature_lock // Validate parents while that job is running for (int i = 0; i < _baseBones.Length; i++) { + if (_baseBones[i] == null || _mergeBones[i] == null || _baseParentBones[i] == null || + _mergeParentBones[i] == null) + { + return false; + } + if (_baseBones[i].parent != _baseParentBones[i] || _mergeBones[i].parent != _mergeParentBones[i]) { return false;