Skip to content

Commit

Permalink
fix: fix null exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Jul 19, 2024
1 parent 53279f9 commit 15d6917
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Packages/src/Runtime/SoftMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public enum MaskingMode

private CommandBuffer _cb;

private List<SoftMask> _children = ListPool<SoftMask>.Rent();
private List<SoftMask> _children;
private bool _hasResolutionChanged;
private bool _hasSoftMaskBufferDrawn;
private Mesh _mesh;
Expand All @@ -103,6 +103,7 @@ public enum MaskingMode
internal RenderTexture _softMaskBuffer;
private UnityAction _updateParentSoftMask;
private CanvasViewChangeTrigger _viewChangeTrigger;
private List<SoftMask> children => _children != null ? _children : _children = ListPool<SoftMask>.Rent();

/// <summary>
/// Masking mode.<br />
Expand Down Expand Up @@ -314,7 +315,7 @@ protected override void OnDisable()
}

UpdateParentSoftMask(null);
_children.Clear();
children.Clear();

MeshExtensions.Return(ref _mesh);
SoftMaskUtils.materialPropertyBlockPool.Return(ref _mpb);
Expand Down Expand Up @@ -576,7 +577,7 @@ private void SetDirtyAndNotify()
private void OnCanvasViewChanged()
{
_hasResolutionChanged = true;
SetSoftMaskDirty();
SetDirtyAndNotify();

#if UNITY_EDITOR
if (!Application.isPlaying)
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 15d6917

Please sign in to comment.