Failed to execute 'elementFromPoint' on 'Document'

TypeError: Failed to execute ‘elementFromPoint’ on ‘Document’: The provided double value is non-finite. at HTMLCanvasElement._onCanvasPointerOut

File: engine.ts

userAgent: Mozilla/5.0 (Linux; Android 11; Pixel 4a) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.101 Mobile Safari/537.36

version: beta 8

proposed fix: provided value should be checked

cc @PolygonalSun

BTW - what were the values that failed? can you reproduce that?

no, sorry, it is a production error message.

For that error to occur, there must something wrong with the pointerout event being fired, specifically, the clientX and clientY values aren’t numbers (or aren’t defined). Usually, these are included by default when the browser fires off a pointerout event. I wonder if there’s either some custom pointerout event that’s firing or if something is affecting those values/preventing them from propagating properly in a browser fired event.

At least that’s my initial thoughts so far.

I’ll see how often it happens. I think it’s fine for now.

1 Like

Any info you can get me on frequency or repro would be appreciated.

I got the error from a second device now:
Mozilla/5.0 (Linux; Android 11; M2102J20SG) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.101 Mobile Safari/537.36

seems like it happens in Android. I’ll leave it up to you if you want to catch the error.

seems like evt.clientX or clientY in this

// Check that the element at the point of the pointer out isn't the canvas and if it isn't, notify observers
            // Note: This is a workaround for a bug with Safari
            if (document.elementFromPoint(ev.clientX, ev.clientY) !== canvas) {

could be NaN of infinity for reasons… on those devices. @RaananW should we simply add a check ? but I am afraid it could be for a different Root Cause.

browser event’s clientX and clientY can’t be NaN. if they are it is the browser’s issue, but i doubt this is the case. it depends on the scenario, but on certain cases we are recreating the event with (what should be) the same values. So it might be during the conversion? What would be the best way to reproduce this? Checking for NaN will be a patch and not a solution.

I’m getting more of these now from all kinds of modern Android phones, any new ideas on how to at least suppress the error?

would be great to see a reproduction of this. Probably an error on our side.
Is this reproducible on the playground in any way?

cc @PolygonalSun - we need to check why this happens and if it’s somewhere in core.

1 Like

I’m pretty sure it doesn’t happen on the couple of Android devices I own myself.
I checked some of the logging again, and it seems to be a bit after this code succesfully runs:

await documentElement.requestFullscreen({ navigationUI: 'hide' });
await screen.orientation?.lock('landscape')

to me it still seems like Chrome should never put NaN there, but not sure…

Hmm… I wonder if that’s causing some kind of loss of context for elementFromPoint. I’ll dig more into this.

Hey @mise, what is the latest version of BJS that you’ve seen these errors on? I know that there was recently a change to _onCanvasPointerOut and I was curious if you were running code that was using that change.

rc3. I will update again soon.

Hi @mise just checking in if you were able to update and if that solved your issue

no, I’m still seeing it, but I also am still on version 5rc3. I’m trying to get a grip on performance, and constant updates from Babylon and the various browsers and OS’s doesn’t make that easier.
Also the last time I tried to update (to rc7 I think) I could not get my project to build anymore and that was not something I wanted to deal with either :).

I’m not in a hurry to solve this issue because I don’t think it’s causing any trouble for my players.