Skip to content

fix(OrbitControls): guard against undefined second pointer position#432

Open
adamistheanswer wants to merge 1 commit into
pmndrs:mainfrom
adamistheanswer:fix/orbit-controls-null-guard
Open

fix(OrbitControls): guard against undefined second pointer position#432
adamistheanswer wants to merge 1 commit into
pmndrs:mainfrom
adamistheanswer:fix/orbit-controls-null-guard

Conversation

@adamistheanswer

Copy link
Copy Markdown

Summary

getSecondPointerPosition() can return undefined when the internal pointerPositions map lacks an entry for the second pointer. This occurs when a pointerup event is lost during tab suspension/resume, leaving stale entries in the pointers array that no longer have matching tracked positions.

Without this guard, callers crash with:

TypeError: Cannot read properties of undefined (reading 'x')

This adds early returns in handleTouchMoveRotate, handleTouchMovePan, and handleTouchMoveDolly to skip the frame rather than crash.

Reproduction

  1. Open a page with OrbitControls on a touch-enabled Linux device (Chromium 149+)
  2. Interact with the canvas (multi-touch gesture)
  3. Switch to another tab / let the session suspend
  4. Return to the tab and interact again
  5. The lost pointerup during suspension leaves stale entries in the internal pointers[] array, causing getSecondPointerPosition() to look up a pointer ID that was never tracked in pointerPositions

Fix

Minimal null guard — if the second pointer's position hasn't been tracked, skip the touch-move frame rather than crashing. The next pointer interaction will re-establish clean state.

Fixes #426
Related mrdoob/three.js#32116

getSecondPointerPosition() can return undefined when the internal
pointerPositions map lacks an entry for the second pointer. This
occurs when a pointerup event is lost during tab suspension/resume,
leaving stale entries in the pointers array that no longer have
matching tracked positions.

Without this guard, callers crash with:
TypeError: Cannot read properties of undefined (reading 'x')

Add early returns in handleTouchMoveRotate, handleTouchMovePan, and
handleTouchMoveDolly to skip the frame rather than crash.

Fixes pmndrs#426
Related mrdoob/three.js#32116
@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OrbitControls touch crashes on Expo mobile app

1 participant