Jump to content

AudioListener error when mouse is moved outside canvas


Recommended Posts

I'm not sure whether this qualifies as a babylon.js bug, but here's my scenario:

  • I'm embedding a babylon.js canvas in a WordPress page
  • there's some audio in the scene, but no positional audio
  • when the mouse is outside the canvas when the canvas loads, and the user moves the mouse, this error is thown, and the canvas crashes:
Uncaught TypeError: Failed to execute 'setPosition' on 'AudioListener': The provided float value is non-finite.
    at i._updateAudioParameters (babylon.custom.js:14)
    at i.render (babylon.custom.js:14)
    at main.js?v=201806111547:595
    at n._renderLoop (babylon.custom.js:6)


You can see it happen here: https://studio.rocketclowns.com/agnes/babylon-test/

Same result in Edge, Chrome and Firefox.


Help :)


Edit: I'm on Windows 10 and babylon.js is version 3.2.0.


Link to comment
Share on other sites


In your code: https://studio.rocketclowns.com/agnes/canvas/rocketLander/main.js?v=201806111547

You're updating the camera position with this code:

            camera.position.x += ((userX * 256) - camera.position.x) * 0.05;
            camera.position.y += ((userY * -128) - camera.position.y) * 0.05;

But scene.pointerX is a undefined at the beginning when the mouse is out the canvas then the camera.position.x & y become NaN and thus the update Audio parameter function fails. 

The solution is either to test for undefined on pointerX and pointerY before computing your position or to register your "mousemove" event on the canvas element rather that on the window object.


Link to comment
Share on other sites

Hello @davrous,

...awesome, thanks for your reply :) 

I changed

window.addEventListener("mousemove", function () {


canvas.addEventListener("mousemove", function () {

and: problem solved!


So: user error and not a babylon.js bug. Maybe this thread can be moved to Q&A?


Thanks again, guys ?



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...