Skip to content

Commit 6fad4bd

Browse files
author
David Kline
authored
Merge pull request #2655 from StephenHodgson/vNEXT-TouchScreen
Fixed collection modification in touch screen input source
2 parents a6a76c7 + d12fcc5 commit 6fad4bd

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

Assets/MixedRealityToolkit/InputSystem/Sources/TouchscreenInputSource.cs

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,39 +144,46 @@ private void AddOrUpdateTouch(Touch touch, Ray ray)
144144

145145
private void RemoveTouch(Touch touch)
146146
{
147+
TouchPointer touchPointer = null;
148+
147149
foreach (var knownTouch in activeTouches)
148150
{
149151
if (knownTouch.TouchData.fingerId == touch.fingerId)
150152
{
151-
if (touch.phase == TouchPhase.Ended)
152-
{
153-
if (knownTouch.Lifetime < K_CONTACT_EPSILON)
154-
{
155-
InputSystem.RaiseHoldCanceled(this, HoldAction);
156-
}
157-
else if (knownTouch.Lifetime < MaxTapContactTime)
158-
{
159-
InputSystem.RaiseHoldCanceled(this, HoldAction);
160-
InputSystem.RaisePointerClicked(knownTouch, PointerAction, knownTouch.TouchData.tapCount);
161-
}
162-
else
163-
{
164-
InputSystem.RaiseHoldCompleted(this, HoldAction);
165-
}
166-
}
167-
else
168-
{
169-
InputSystem.RaiseHoldCanceled(this, HoldAction);
170-
}
153+
touchPointer = knownTouch;
154+
break;
155+
}
156+
}
171157

172-
InputSystem.RaisePointerUp(knownTouch, PointerAction);
173-
activeTouches.Remove(knownTouch);
158+
if (touchPointer == null) { return; }
174159

175-
if (activeTouches.Count == 0)
176-
{
177-
InputSystem.RaiseSourceLost(this);
178-
}
160+
if (touch.phase == TouchPhase.Ended)
161+
{
162+
if (touchPointer.Lifetime < K_CONTACT_EPSILON)
163+
{
164+
InputSystem.RaiseHoldCanceled(this, HoldAction);
179165
}
166+
else if (touchPointer.Lifetime < MaxTapContactTime)
167+
{
168+
InputSystem.RaiseHoldCanceled(this, HoldAction);
169+
InputSystem.RaisePointerClicked(touchPointer, PointerAction, touchPointer.TouchData.tapCount);
170+
}
171+
else
172+
{
173+
InputSystem.RaiseHoldCompleted(this, HoldAction);
174+
}
175+
}
176+
else
177+
{
178+
InputSystem.RaiseHoldCanceled(this, HoldAction);
179+
}
180+
181+
InputSystem.RaisePointerUp(touchPointer, PointerAction);
182+
activeTouches.Remove(touchPointer);
183+
184+
if (activeTouches.Count == 0)
185+
{
186+
InputSystem.RaiseSourceLost(this);
180187
}
181188
}
182189

0 commit comments

Comments
 (0)