OrbitControls touch crashes on Expo mobile app
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- javascript, three.js
- Domain
- frontend, mobile-dev
Research direction
Start in OrbitControls.js at _getSecondPointerPosition() and the listed touch handlers, then reproduce the two-finger pinch and finger-lift sequence with the linked Expo sample project. Done means the gesture no longer crashes when the second pointer position is undefined, including the listed rotate, pan, and dolly paths.
Written by the indexing model from the issue text.
Description
threeversion: ^0.166.1@types/threeversion: 0.183.1three-stdlibversion: ^2.35.6
Problem description:
As previously reported by @damistheanswer in the issue https://github.com/mrdoob/three.js/issues/32116, OrbitControls does crash a mobile app on touch devices, such tablets and iPads, when using multi-touches to zoom in/zoom out an object.
I got the same message such as:
TypeError: Cannot read properties of undefined (reading 'x')
Reproduction steps
- Download the sample project or the apk file
- 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
Relevant code:
Same as the issue #32116
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
Same as the issue #32116:
- User starts two-finger gesture → both pointers tracked in _pointers array
- User lifts one finger → pointer is removed from _pointers
- Move event fires for remaining finger → tries to get second pointer position
- _pointerPositions[pointerId] returns undefined because pointer was removed
- Code attempts position.x → crash
Screenshots
Attached error on expo app:
Please check this video for demonstration of the bug:
Device
Mobile
OS
Android
- Dominant language
- JavaScript
- Stars
- 863
- Forks
- 146
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pmndrs/three-stdlib
-
SSAOPass height type error,It's number not booleanPossibly taken @Techsynx claimed this 23 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 62/100
pmndrs/three-stdlib#423 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
pmndrs/three-stdlib#437 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 42/100
pmndrs/three-stdlib#435 ·
-
Update MeshOpt v1Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
pmndrs/three-stdlib#425 ·
-
RangeError: Maximum call stack size exceeded when exporting to gilt file using GLTFExporterMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
pmndrs/three-stdlib#414 ·
All issues in pmndrs/three-stdlib
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Forrest-Technologies/drover#1040 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 90/100
erkamyaman/rust-anything#702 ·
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
erkamyaman/unslop-anything#231 ·
Maintainers usually reply within 1 day
