Skip to content

Commit 01a0d7a

Browse files
FIX: inactive touch driving invalid synthetic click on state reset (#2349)
Co-authored-by: Rita Merkl <127492464+ritamerkl@users.noreply.github.com>
1 parent 2a986f9 commit 01a0d7a

File tree

4 files changed

+260
-66
lines changed

4 files changed

+260
-66
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,45 @@ public void Actions_ValueActionsEnabledInOnEvent_DoNotReactToCurrentStateOfContr
14041404
}
14051405
}
14061406

1407+
// Regression test for UUM-100125.
1408+
[Test]
1409+
[Category("Actions")]
1410+
public void Actions_InitialStateCheckAfterConfigurationChange_DoesNotTriggerForInactiveTouch()
1411+
{
1412+
var touchscreen = InputSystem.AddDevice<Touchscreen>();
1413+
var action = new InputAction(type: InputActionType.Value, binding: "<Touchscreen>/primaryTouch/position");
1414+
action.Enable();
1415+
1416+
// Run the first initial state check from enabling the action.
1417+
InputSystem.Update();
1418+
1419+
using (var trace = new InputActionTrace(action))
1420+
{
1421+
BeginTouch(1, new Vector2(123, 234));
1422+
EndTouch(1, new Vector2(345, 456));
1423+
1424+
Assert.That(touchscreen.primaryTouch.isInProgress, Is.False);
1425+
Assert.That(touchscreen.primaryTouch.position.ReadValue(), Is.Not.EqualTo(default(Vector2)));
1426+
1427+
trace.Clear();
1428+
1429+
// Configuration change causes full re-resolve and schedules initial state check.
1430+
InputSystem.QueueConfigChangeEvent(touchscreen);
1431+
InputSystem.Update();
1432+
InputSystem.Update();
1433+
1434+
// Full re-resolve may cancel the current action state. What must NOT happen is a synthetic
1435+
// Started/Performed pair from persisted inactive touch state.
1436+
Assert.AreEqual(1, trace.count);
1437+
foreach (var eventPtr in trace)
1438+
{
1439+
// The trace should only contain a Canceled event for the action.
1440+
Assert.AreEqual(InputActionPhase.Canceled, eventPtr.phase,
1441+
$"inactive touch state should not produce action callbacks, but received {eventPtr.phase}.");
1442+
}
1443+
}
1444+
}
1445+
14071446
// https://fogbugz.unity3d.com/f/cases/1192972/
14081447
[Test]
14091448
[Category("Actions")]
@@ -12484,17 +12523,20 @@ public void Actions_WithMultipleCompositeBindings_WithoutEvaluateMagnitude_Works
1248412523

1248512524
// Now when enabling actionMap ..
1248612525
actionMap.Enable();
12487-
// On the following update we will trigger OnBeforeUpdate which will rise started/performed
12488-
// from InputActionState.OnBeforeInitialUpdate as controls are "actuated"
12526+
// Inactive touches (ended before action was enabled) must NOT produce started/performed from
12527+
// OnBeforeInitialUpdate. Their persisted state (position, touchId) is non-default due to
12528+
// dontReset, but only TouchControl.isInProgress should be considered for initial-state check.
12529+
// Related to UUM-100125 and Actions_InitialStateCheckAfterConfigurationChange_DoesNotTriggerForInactiveTouch.
1248912530
InputSystem.Update();
12490-
Assert.That(values.Count, Is.EqualTo(prepopulateTouchesBeforeEnablingAction ? 2 : 0)); // started+performed arrive from OnBeforeUpdate
12531+
Assert.That(values.Count, Is.EqualTo(0));
1249112532
values.Clear();
1249212533

12493-
// Now subsequent touches should not be ignored
1249412534
BeginTouch(200, new Vector2(1, 1));
12495-
Assert.That(values.Count, Is.EqualTo(1));
12496-
Assert.That(values[0].InputId, Is.EqualTo(200));
12497-
Assert.That(values[0].Position, Is.EqualTo(new Vector2(1, 1)));
12535+
// If prepopulated, action was never actuated (synthetic initial-check is suppressed),
12536+
// so BeginTouch fires started+performed (2 events).
12537+
Assert.That(values.Count, Is.EqualTo(prepopulateTouchesBeforeEnablingAction ? 2 : 1));
12538+
Assert.That(values[values.Count - 1].InputId, Is.EqualTo(200));
12539+
Assert.That(values[values.Count - 1].Position, Is.EqualTo(new Vector2(1, 1)));
1249812540
}
1249912541

1250012542
// FIX: This test is currently checking if shortcut support is enabled by testing that the unwanted behaviour exists.

0 commit comments

Comments
 (0)