Skip to content

Commit 681acd2

Browse files
committed
Added check on application quit to avoid gameobject lookup
1 parent 4646eb3 commit 681acd2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Assets/Kekser/PowerSingleton/PowerSingletonManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private struct PowerSingletonData
2626

2727
private static readonly Dictionary<Type, List<PowerSingletonData>> _powerSingletons = new Dictionary<Type, List<PowerSingletonData>>();
2828
private static bool _initialized;
29+
private static bool _quitting;
2930

3031
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
3132
public static void Initialize()
@@ -34,10 +35,16 @@ public static void Initialize()
3435
{
3536
LookUpAttributes();
3637
SceneManager.activeSceneChanged += (arg0, arg1) => Initialize();
38+
Application.quitting += Quitting;
3739
_initialized = true;
3840
}
3941
AutoCreate();
4042
}
43+
44+
private static void Quitting()
45+
{
46+
_quitting = true;
47+
}
4148

4249
private static bool TryAddToDictionary<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
4350
{
@@ -105,6 +112,9 @@ private static void AutoCreate()
105112

106113
public static Object Get(Type type)
107114
{
115+
if (_quitting)
116+
return null;
117+
108118
Object instance = null;
109119
if (!_powerSingletons.ContainsKey(type))
110120
{

Assets/Kekser/PowerSingleton/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.kekser.powersingleton",
33
"displayName": "PowerSingleton",
44
"author": { "name": "Kekser", "url": "https://github.com/DerKekser" },
5-
"version": "1.3.1",
5+
"version": "1.3.2",
66
"unity": "2020.3",
77
"description": "A simple singleton system for Unity",
88
"keywords": [ "singleton" ],

0 commit comments

Comments
 (0)