-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Open
Labels
Description
Description
OrbitControls crashes intermittently on touch devices (tablets) during multi-touch gestures with the error:
TypeError: Cannot read properties of undefined (reading 'x')
This occurs in the _getSecondPointerPosition() method when handling two-finger pinch-to-zoom gestures.
Reproduction steps
- Open a three.js scene with OrbitControls on a tablet device (Android)
- Start a two-finger pinch gesture (pinch-to-zoom)
- Lift one finger mid-gesture while the other finger remains touching
- The error occurs sporadically when the second pointer position becomes undefined
Code
In OrbitControls.js, the _getSecondPointerPosition() method returns undefined when a pointer is no longer tracked:
// Line ~1407-1411
_getSecondPointerPosition( event ) {
const pointerId = ( event.pointerId === this._pointers[ 0 ] ) ? this._pointers[ 1 ] : this._pointers[ 0 ];
return this._pointerPositions[ pointerId ]; // Can return undefined!
}This undefined value is then used without null checking in multiple places:
// Line ~1234-1238 (handleTouchMoveDolly)
const position = this._getSecondPointerPosition( event );
const dx = event.pageX - position.x; // ❌ Crash: position is undefined
const dy = event.pageY - position.y;Similar crashes occur at:
- Line 1202-1204 (handleTouchStartRotate)
- Line 1221-1223 (handleTouchStartPan)
- Line 1269-1271 (handleTouchMoveRotate)
- Line 1298-1300 (handleTouchMovePan)
- Line 1317-1320 (handleTouchMoveDolly)
Live example
- User starts two-finger gesture → both pointers tracked in
_pointersarray - User lifts one finger → pointer is removed from
_pointers - Move event fires for remaining finger → tries to get second pointer position
_pointerPositions[pointerId]returnsundefinedbecause pointer was removed- Code attempts
position.x→ crash
Screenshots
No response
Version
v0.180.0
Device
Mobile
Browser
Chrome
OS
Android