Skip to content

Commit 45932af

Browse files
FIX: Fix for the event buffer growing unbounded in Editor when a controller is connected and certain options are set (#1636)
1 parent 670f833 commit 45932af

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ however, it has to be formatted properly to pass verification tests.
1313
### Fixed
1414
- Fixed unclosed profiler marker in `InvokeCallbacksSafe_AnyCallbackReturnsTrue` which would lead to eventually broken profiler traces in some cases like using `PlayerInput` (case ISXB-393).
1515
- Fixed InputAction.bindings.count not getting correctly updated after removing bindings with Erase().
16+
- Fixed an issue where connecting a gamepad in the editor with certain settings will cause memory and performance to degrade ([case UUM-19480](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-19480)).
1617

1718
## [1.5.0] - 2023-01-24
1819

Packages/com.unity.inputsystem/InputSystem/InputManager.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,6 +2881,19 @@ private unsafe void OnUpdate(InputUpdateType updateType, ref InputEventBuffer ev
28812881
#endif
28822882
);
28832883

2884+
2885+
bool dropStatusEvents = false;
2886+
2887+
#if UNITY_EDITOR
2888+
if (!gameIsPlaying && gameShouldGetInputRegardlessOfFocus && (eventBuffer.sizeInBytes > (100 * 1024)))
2889+
{
2890+
// If the game is not playing but we're sending all input events to the game, the buffer can just grow unbounded.
2891+
// So, in that case, set a flag to say we'd like to drop status events, and do not early out.
2892+
canEarlyOut = false;
2893+
dropStatusEvents = true;
2894+
}
2895+
#endif
2896+
28842897
if (canEarlyOut)
28852898
{
28862899
// Normally, we process action timeouts after first processing all events. If we have no
@@ -2952,6 +2965,19 @@ private unsafe void OnUpdate(InputUpdateType updateType, ref InputEventBuffer ev
29522965
var currentEventTimeInternal = currentEventReadPtr->internalTime;
29532966
var currentEventType = currentEventReadPtr->type;
29542967

2968+
#if UNITY_EDITOR
2969+
if (dropStatusEvents)
2970+
{
2971+
// If the type here is a status event, ask advance not to leave the event in the buffer. Otherwise, leave it there.
2972+
if (currentEventType == StateEvent.Type || currentEventType == DeltaStateEvent.Type || currentEventType == IMECompositionEvent.Type)
2973+
m_InputEventStream.Advance(false);
2974+
else
2975+
m_InputEventStream.Advance(true);
2976+
2977+
continue;
2978+
}
2979+
#endif
2980+
29552981
// In the editor, we discard all input events that occur in-between exiting edit mode and having
29562982
// entered play mode as otherwise we'll spill a bunch of UI events that have occurred while the
29572983
// UI was sort of neither in this mode nor in that mode. This would usually lead to the game receiving

0 commit comments

Comments
 (0)