Skip to content

Commit

Permalink
单例对象销毁时的检查,修正由此错误的销毁单例对象的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
沈挺 committed Jul 9, 2024
1 parent 9afda78 commit e53ceb0
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ protected virtual void OnLoad()

protected virtual void OnDestroy()
{
Release();
if (this == _instance)
{
Release();
}
}

/// <summary>
Expand All @@ -60,7 +63,7 @@ public static void Release()
if (_instance != null)
{
SingletonSystem.Release(_instance.gameObject);
_instance = null;
_instance = null;
}
}

Expand Down Expand Up @@ -96,7 +99,7 @@ public static T Instance
}
}

if(_instance == null)
if (_instance == null)
{
Log.Error($"Can't create SingletonBehaviour<{typeof(T)}>");
}
Expand Down

0 comments on commit e53ceb0

Please sign in to comment.