AlbertTJames Posted September 23, 2016 Share Posted September 23, 2016 Hey everyone I am not sure why but if I create two ScreenSpaceCanvas2D in two different scenes, one of the scenes being shown and not the other (stored in a parent object). The function Canvas2D.prototype._updatePointerInfo is called twice each time I move the mouse, once for the shown Canvas, and once for the canvas that is in the stored scene. Since I did not declare a camera in that stored scene the bit of code in babylon.max.js 44657 : Canvas2D.prototype._updatePointerInfo = function (eventData, localPosition) { ... var camera = this._scene.cameraToUseForPointers || this._scene.activeCamera; ... } return camera as undefined. And later on while the function tries to access camera.viewport it returns an error. This report is not really about solving the bug because if I declare a random camera for the stored scene (like a normal human being not trying to find bugs everywhere) i do not get the error. But I think it was not on purpose that events are captured on a canvas in a scene that is not currently rendered. All in all it is not a real problem for me but it might cause trouble for other people. To change between scenes I use this bit of code /* --- Start the render loop --- */ taskObject.engine.runRenderLoop(function () { taskObject.scenes[taskObject.currentScene].render(); }); This is the call stack for the error: Uncaught TypeError: Cannot read property 'viewport' of undefined @babylon.max.js:44665 Canvas2D._updatePointerInfo @ babylon.max.js:44665 Canvas2D._handlePointerEventForInteraction @ babylon.max.js:44628 (anonymous function) @ babylon.max.js:44549 Observable.notifyObservers @ babylon.max.js:3399 _onPointerMove @ babylon.max.js:15232 It seems the observables are set up at scene creation and down the callback chain there is no test to check wether the scene is currently being rendered (is that even possible?). Quote Link to comment Share on other sites More sharing options...
Nockawa Posted September 23, 2016 Share Posted September 23, 2016 Hello, I take a look at your issue right now Quote Link to comment Share on other sites More sharing options...
Nockawa Posted September 23, 2016 Share Posted September 23, 2016 First, thanks for reporting the issue so clearly. I have question though: Quote one of the scenes being shown and not the other (stored in a parent object) Maybe @Deltakosh would know, but I don't really know if there's a concept of an "active scene", as you're in charge of the renderLoop and you decide which scene is rendered and which ones are not, I don't know how I can detect that and behave accordingly. Note that you can change the Canvas2D.interactionEnabled property which will turn off/on interaction, if you maintain interaction On for only the "activeScene" then things should be alright. In the mean time I've added code guards to check for the error you mentioned, it's the least I can do. Now I'd like to know if I can do more, DK will certainly tell us. Edit: I just commit/merged the fix AlbertTJames 1 Quote Link to comment Share on other sites More sharing options...
AlbertTJames Posted September 24, 2016 Author Share Posted September 24, 2016 That was quick ! thanks 4 hours ago, Nockawa said: Note that you can change the Canvas2D.interactionEnabled property which will turn off/on interaction, if you maintain interaction On for only the "activeScene" then things should be alright. Indeed, I thought I had to report the issue anyway Nockawa 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.