From b95042998963c42a82377900a11abfdefd1e54d9 Mon Sep 17 00:00:00 2001 From: Adam Robinson Date: Mon, 15 Jun 2026 11:06:36 +0100 Subject: [PATCH] fix(OrbitControls): guard against undefined second pointer position 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 https://github.com/pmndrs/three-stdlib/issues/426 Related https://github.com/mrdoob/three.js/issues/32116 --- src/controls/OrbitControls.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/controls/OrbitControls.ts b/src/controls/OrbitControls.ts index ab1dc193..dcc43411 100644 --- a/src/controls/OrbitControls.ts +++ b/src/controls/OrbitControls.ts @@ -777,6 +777,7 @@ class OrbitControls extends EventDispatcher { rotateEnd.set(event.pageX, event.pageY) } else { const position = getSecondPointerPosition(event) + if (!position) return const x = 0.5 * (event.pageX + position.x) const y = 0.5 * (event.pageY + position.y) rotateEnd.set(x, y) @@ -798,6 +799,7 @@ class OrbitControls extends EventDispatcher { panEnd.set(event.pageX, event.pageY) } else { const position = getSecondPointerPosition(event) + if (!position) return const x = 0.5 * (event.pageX + position.x) const y = 0.5 * (event.pageY + position.y) panEnd.set(x, y) @@ -810,6 +812,7 @@ class OrbitControls extends EventDispatcher { function handleTouchMoveDolly(event: PointerEvent) { const position = getSecondPointerPosition(event) + if (!position) return const dx = event.pageX - position.x const dy = event.pageY - position.y const distance = Math.sqrt(dx * dx + dy * dy)