pmndrs / drei

🥉 useful helpers for react-three-fiber
https://drei.pmnd.rs/
MIT License
7.83k stars 642 forks source link

PointerLockControls: Can't lock pointer back immediately after escape #1988

Open satelllte opened 3 weeks ago

satelllte commented 3 weeks ago

Version

Problem description

Some browsers like Chrome don't allow to lock pointer immediately after unlocking it. This is why this error is logged when user tries to do it:

THREE.PointerLockControls: Unable to use Pointer Lock API @ PointerLockControls.ts:61
Uncaught (in promise) DOMException: The user has exited the lock before this request was completed.

Reproduction steps

Potential solution

As far as I'm aware, this issue can't be solved entirely due to the native behaviour of browsers, but maybe there are some ways to have an API for PointerLockControls, which could tell consumers when the pointer is allowed to be locked again, so they can handle it to have a better UX.

Video demo

https://github.com/pmndrs/drei/assets/20585619/2d61c24a-422a-4110-8fbd-1c9d10928105

Related topics

Wyundi commented 2 weeks ago

It is a "feature" of Chrome. We use a timer to avoid that.