onPrePointerObservable sometimes runs twice for same pointer event?

Hey team…
I notised issues with the GUI in latest preview, clicking a GUI button will randomly run the pointer observables twice sometimes.

Sometimes you can make 10-20 clicks with no problems, and sometimes it can run twice 3-4 clicks in a row.

I haven’t found the exact root of the problem, but it appears to exist already on the scene.onPrePointerObservable

It’s a bit tough to give a good repro :slight_smile:
This PG makes 4 log messages per pointer click (2 per down & 2 per up)
Switching between left & right clicks seems to reproduce the error often.

cc @PolygonalSun and @carolhmj in case it rings a bell.

If it helps, the extra observables always happens after the pointer up has run.
Primarily on right clicks.
I managed to replicate on v5.71.1 too.

Just never had issues with it until now.

As a temporary fix, you could add your own debounce wrapper:

function debounce(func, timeout = 300){
let timer;
let ready = true;

return (...args) => {
  if (ready) {
      func.apply(this, args); 
  ready = false;
  timer = setTimeout(() => { ready = true}, timeout);


let myClickAction = debounce(myClickAction);

Then when you run myClickAction, it doesn’t allow it to fire more than once every 300 ms.

From what I’m seeing, it looks like the extra prepointer log is coming from a move event with a non -1 value for button. Lemme take a closer look.

I digged a bit further, seeing the erorr already at scene._inputManager._deviceSourceManager._onInputChanged

At which point the code gets pretty convoluted and hard to follow further, in the PG at least.

Okay… It’s actually not babylonjs.

its… windows or V8 ??
Test latest Chrome, lastest Opera, lastest Edge

Downloaded Firefox, it happens in SpiderMonkey too, so it’s assumeably not V8 ?