Skip to content

Commit 3a0bd98

Browse files
committed
fix(ui): 修复 OnClose 中潜在的空引用异常
在 OnClose 方法中增加 this 和 gameObject 的空值检查, 避免在对象已销毁时触发 NullReferenceException。
1 parent 4ff9dc9 commit 3a0bd98

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Runtime/UIForm.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,14 @@ public virtual void UpdateLocalization()
699699
[UnityEngine.Scripting.Preserve]
700700
public virtual void OnClose(bool isShutdown, object userData)
701701
{
702-
gameObject?.SetLayerRecursively(m_OriginalLayer);
702+
if (this != null)
703+
{
704+
var currentGameObject = gameObject;
705+
if (currentGameObject != null)
706+
{
707+
currentGameObject.SetLayerRecursively(m_OriginalLayer);
708+
}
709+
}
703710

704711
m_Available = false;
705712
Visible = false;

0 commit comments

Comments
 (0)