From 23b0b2c72ab33680c9791a2fbd148e4819bb1a42 Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Sat, 20 Jul 2024 01:52:37 +0900 Subject: [PATCH] fix: fix null exception --- Runtime/SoftMask.cs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Runtime/SoftMask.cs b/Runtime/SoftMask.cs index a59281b..05f6a46 100644 --- a/Runtime/SoftMask.cs +++ b/Runtime/SoftMask.cs @@ -87,7 +87,7 @@ public enum MaskingMode private CommandBuffer _cb; - private List _children = ListPool.Rent(); + private List _children; private bool _hasResolutionChanged; private bool _hasSoftMaskBufferDrawn; private Mesh _mesh; @@ -103,6 +103,7 @@ public enum MaskingMode internal RenderTexture _softMaskBuffer; private UnityAction _updateParentSoftMask; private CanvasViewChangeTrigger _viewChangeTrigger; + private List children => _children != null ? _children : _children = ListPool.Rent(); /// /// Masking mode.
@@ -314,7 +315,7 @@ protected override void OnDisable() } UpdateParentSoftMask(null); - _children.Clear(); + children.Clear(); MeshExtensions.Return(ref _mesh); SoftMaskUtils.materialPropertyBlockPool.Return(ref _mpb); @@ -576,7 +577,7 @@ private void SetDirtyAndNotify() private void OnCanvasViewChanged() { _hasResolutionChanged = true; - SetSoftMaskDirty(); + SetDirtyAndNotify(); #if UNITY_EDITOR if (!Application.isPlaying) @@ -588,19 +589,19 @@ private void OnCanvasViewChanged() public void SetSoftMaskDirty() { - if (isDirty) return; + if (isDirty || !this || !isActiveAndEnabled) return; Logging.LogIf(!isDirty, this, $"! SetSoftMaskDirty {GetInstanceID()}"); isDirty = true; - for (var i = _children.Count - 1; i >= 0; i--) + for (var i = children.Count - 1; i >= 0; i--) { - if (_children[i]) + if (children[i]) { - _children[i].SetSoftMaskDirty(); + children[i].SetSoftMaskDirty(); } else { - _children.RemoveAt(i); + children.RemoveAt(i); } } } @@ -641,14 +642,14 @@ private void UpdateParentSoftMask() private void UpdateParentSoftMask(SoftMask newParent) { - if (_parent && _parent._children.Contains(this)) + if (_parent && _parent.children.Contains(this)) { - _parent._children.Remove(this); + _parent.children.Remove(this); } - if (newParent && !newParent._children.Contains(this)) + if (newParent && !newParent.children.Contains(this)) { - newParent._children.Add(this); + newParent.children.Add(this); } if (_parent != newParent)