Skip to content

Commit

Permalink
fix(pointers): [iOS] Fix frame id capping to uint.MaxValue (Breaks Dr…
Browse files Browse the repository at this point in the history
…ag and Drop after about 10 days of device uptime with latests version of iOS)
  • Loading branch information
dr1rrb authored and jeromelaban committed May 24, 2022
1 parent 8723d04 commit 2a08809
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Uno.UI/UI/Xaml/Input/PointerRoutedEventArgs.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,23 @@ private PointerPointProperties GetProperties()

private static ulong ToTimeStamp(double timestamp)
{
if (!_bootTime.HasValue)
{
_bootTime = DateTime.UtcNow.Ticks - (long)(TimeSpan.TicksPerSecond * new NSProcessInfo().SystemUptime);
}
_bootTime ??= DateTime.UtcNow.Ticks - (long)(TimeSpan.TicksPerSecond * new NSProcessInfo().SystemUptime);

return (ulong)_bootTime.Value + (ulong)(TimeSpan.TicksPerSecond * timestamp);
}

private static double? _firstTimestamp;

private static uint ToFrameId(double timestamp)
{
// The precision of the frameId is 10 frame per ms ... which should be enough
return (uint)(timestamp * 1000.0 * 10.0);
_firstTimestamp ??= timestamp;

var relativeTimestamp = timestamp - _firstTimestamp;
var frameId = relativeTimestamp * 120.0; // we allow a precision of 120Hz (8.333 ms per frame)

// When we cast, we are not overflowing but instead capping to uint.MaxValue.
// We use modulo to make sure to reset to 0 in that case (1.13 years of app run-time, but we prefer to be safe).
return (uint)(frameId % uint.MaxValue);
}

private static UIElement FindOriginalSource(UITouch touch)
Expand Down

0 comments on commit 2a08809

Please sign in to comment.