Skip to content

Commit f7fbc7f

Browse files
committed
Refactor GlobalState usages to re-initialize statics (ISX-1840)
- Static field (in each class) initialized via RuntimeInitializeOnLoadMethod() hook - This functionality is a bit clunky and should be refactored but that's out-of-scope for this work
1 parent 2b7be8e commit f7fbc7f

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs

+7
Original file line numberDiff line numberDiff line change
@@ -4234,6 +4234,13 @@ internal struct GlobalState
42344234

42354235
internal static GlobalState s_GlobalState;
42364236

4237+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
4238+
private static void InitializeGlobalActionState()
4239+
{
4240+
ResetGlobals();
4241+
s_GlobalState = default;
4242+
}
4243+
42374244
internal static ISavedState SaveAndResetState()
42384245
{
42394246
// Save current state

Packages/com.unity.inputsystem/InputSystem/Plugins/EnhancedTouch/Touch.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,14 @@ internal struct GlobalState
593593
#endif
594594
}
595595

596-
private static GlobalState CreateGlobalState()
597-
{ // Convenient method since parameterized construction is default
598-
return new GlobalState { historyLengthPerFinger = 64 };
599-
}
596+
internal static GlobalState s_GlobalState;
600597

601-
internal static GlobalState s_GlobalState = CreateGlobalState();
598+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
599+
private static void InitializeGlobalTouchState()
600+
{
601+
// Touch GlobalState doesn't require Dispose operations
602+
s_GlobalState = new GlobalState { historyLengthPerFinger = 64 };
603+
}
602604

603605
internal static ISavedState SaveAndResetState()
604606
{
@@ -609,7 +611,7 @@ internal static ISavedState SaveAndResetState()
609611
() => { /* currently nothing to dispose */ });
610612

611613
// Reset global state
612-
s_GlobalState = CreateGlobalState();
614+
InitializeGlobalTouchState();
613615

614616
return savedState;
615617
}

Packages/com.unity.inputsystem/InputSystem/Plugins/Users/InputUser.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,13 @@ private struct GlobalState
18731873

18741874
private static GlobalState s_GlobalState;
18751875

1876+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
1877+
private static void InitializeGlobalUserState()
1878+
{
1879+
ResetGlobals();
1880+
s_GlobalState = default;
1881+
}
1882+
18761883
internal static ISavedState SaveAndResetState()
18771884
{
18781885
// Save current state and provide an opaque interface to restore it

0 commit comments

Comments
 (0)