Skip to content

iOS touch IDs are unstable - reassigned when touches are added/removed #589

Open

Description

@designspin

I think touch IDs on iOS are unstable and change when new touches are added or removed, breaking multitouch tracking. The IDs are just array indices (0, 1, 2...) rather than stable identifiers tied to the actual UITouch objects.

Steps to Reproduce

  1. Touch the screen with one finger (gets ID 0)
  2. While keeping first finger down, touch with a second finger
  3. Observe that the first touch now has ID 1 and the second touch has ID 0

Root Cause

In src/native/ios.rs lines 139-154, the code uses a loop counter as the touch ID:

for touch_id in 0..size {
    let ios_touch: ObjcId = msg_send![enumerator, nextObject];
    // ...
    send_message(Message::Touch {
        phase,
        touch_id,  // This is just 0, 1, 2... not a stable ID
        // ...
    });
}

Suggested Fix

Use the UITouch pointer itself as the touch ID:

for _ in 0..size {
    let ios_touch: ObjcId = msg_send![enumerator, nextObject];
    let touch_id: u64 = ios_touch as u64;  // Use pointer as stable ID
    // ...
}

Impact

Any application using touch IDs to track individual fingers (e.g., dual-stick controls, multitouch gestures) will fail with more than one simultaneous touch.
Environment
miniquad version: 0.4.8
Platform: iOS (tested on iPhone 16, iOS 18.6.2)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions