From 3f50da35f23960a22dabbd5c3ea63e1221ad200c Mon Sep 17 00:00:00 2001 From: bd_ Date: Sun, 10 Mar 2024 19:20:34 -0700 Subject: [PATCH] fix: potential null ref exceptions from scale adjuster (#767) --- Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs | 6 ++++++ Runtime/ScaleAdjuster/ProxyManager.cs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs b/Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs index 1b8dbbae..6e8da683 100644 --- a/Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs +++ b/Runtime/ScaleAdjuster/ModularAvatarScaleAdjuster.cs @@ -54,6 +54,12 @@ namespace nadena.dev.modular_avatar.core internal void PreCull() { + if (this == null) + { + EditorApplication.delayCall += () => ProxyManager.UnregisterAdjuster(this); + return; + } + if (PrefabUtility.IsPartOfPrefabAsset(this)) return; if (scaleProxyChild == null || initialized == false) diff --git a/Runtime/ScaleAdjuster/ProxyManager.cs b/Runtime/ScaleAdjuster/ProxyManager.cs index 7956630f..4fa08898 100644 --- a/Runtime/ScaleAdjuster/ProxyManager.cs +++ b/Runtime/ScaleAdjuster/ProxyManager.cs @@ -102,9 +102,13 @@ namespace nadena.dev.modular_avatar.core // Give each adjuster a chance to initialize the bone mappings first foreach (var adj in _capturedAdjusters) { + if (adj == null) + { + _capturedAdjusters = _adjusters = _adjusters.Remove(adj); + } adj.PreCull(); } - + foreach (var kvp in _originalToReplacementBone) { if (kvp.Key == null || kvp.Value == null) @@ -255,6 +259,10 @@ namespace nadena.dev.modular_avatar.core foreach (var adj in _capturedAdjusters) { + if (adj == null) + { + _capturedAdjusters = _capturedAdjusters.Remove(adj); + } adj.PreCull(); // update scale }