Hey there
!
Recently, I used a Samsung tablet with its S Pen on the arc rotate camera playground example.
I noticed that when using the S Pen to for e.g. rotate the camera after the 4th interaction the camera always freezes (no interactions possible anymore). I.e. trying to rotate the camera the 5th time doesn’t work anymore.
After connecting the tablet to my laptop and using chrome://inspect/#devices to connect the Chrome DevTools I noticed that Babylon.js prints
logger.ts:107 BJS - [09:10:45]: Max number of touches exceeded. Ignoring touches in excess of 5
This message seems to originate from webDeviceInputSystem.ts either in this._pointerDownEvent or this._pointerMoveEvent.
This problem happens only when using the S Pen (not sure if it happens also on any other tablet with a “pen”). Furthermore, one can “clear” the activeTouchIds by e.g. clicking on a button (that’s why I’m clicking on the hamburger menu) and then the next 4 interactions work again until the 5th.
This problem doesn’t happen when using my finger:
When starting to set a breakpoint in this._pointerDownEvent I can observe that the array _activeTouchIds gets populated multiple times with the same pointerId (in the example 12).

Interestingly, I was able to reproduce this behavior without a tablet and only using Chrome on my laptop by putting a breakpoint in this._pointerDownEvent. Of course, now there are only 2 instead of 5 slots, but the behavior seems to be the same/similar.
Without a breakpoint the issue doesn’t occur.
TL;DR:
Somehow it seems that the activeTouchId of a pen isn’t correctly “released” causing the available slots to be filled up until hitting the maximum.
The fact that this also happens without a tablet + pen but with a set breakpoint gives the impression that it could maybe be a timing issue which only gets evident when using a pen
. But this is just a guess.
Is anyone able to reproduce this issue and might have an idea what the problem/solution is?
Thanks a lot!
Update
I just realized that a pointermove event gets triggered as soon as the pen is hovering close enough over the screen (but doesn’t touch it yet).

Could it be, that the same pointerId gets “retroactively connected” in this._pointerMoveEvent after the pen was lifted (i.e. pointerup was triggered).
I.e. maybe we can’t always “retroactively connect” a pointerId on pointermove event, since a pointermove gets triggered by the pen already when hovering over the screen. This is probably a different behavior then when using a finger, since a finger needs to be always touching the screen in order to trigger a pointermove event.
I.e. do we need to add an additional check in webDeviceInputSystem.ts#L428-L447? E.g. check if a pointerdown was first triggered for the given pointerId before we “retroactively connect” it
?