Resize continually firing?

So I have a scene/project that is way to complex to remake in a PG buuuuut am hoping someone might have an idea where I could start looking to solve this.

Essentially once and a while it seems like the engine.onResizeObservable continually fires after one time.

I have come to this conclusion because I have a scene optimizer that reruns after a set time after a resize but it was constantly outputting that it was resting.

So I stripped everything down and just did
engine.onResizeObservable.add(()=>{
console.log(“EngineResize”)
})

and it started just firing that constantly after the initial window resize.

Assumingly this is a client/project problem but I kind of am at a loss of where to dig for this because it does not do it in a PG.

Only guess I can think of is if you added a callback to onResizeObservable that calls engine.resize() or calls something else that eventually calls that, creating an infinite cycle… :thinking:

As you said, hard to be sure without details of your project setup or code. But the two common reasons I’ve seen for symptoms like this:

  • Something in the resize handler itself triggers a canvas resize (or a Babylon Engine setSize), and that then becomes recursive/infinite.

  • Whatever is subscribing to resize events does not unsubscribe before another resubscribe is triggered. This is common in hot reload dev environments.

You might try isolating by watching the window resize events independent of Babylon. i.e.

    const now = new Date()
    engine.onResizeObservable.add(()=>{
        console.log("EngineResize: " + now.getTime())
    })

    const evtListener = () => {
        console.log("WindowResize: " + now.getTime());
    }
    window.addEventListener("resize", evtListener);
    scene.onDisposeObservable.add(() => {
        window.removeEventListener("resize", evtListener);
    })

Example PG: https://playground.babylonjs.com/#Y2PTYT#1

Using the PG, you can see an example of the second issue I mentioned by commenting out the removeEventListener. If you do, then every time you click play will result in an additional log event upon resize. At least until you reload the page in the browser, which clears all listeners.

1 Like

so does setHardwardScalingLevel trigger a resize?

Yep looks like that’s the culprit if you’re calling it in your onResizeObservable callback…

2 Likes

Confirming. Results in engine resize event: https://playground.babylonjs.com/#Y2PTYT#4

2 Likes

Did not even think that method did that, good catch, now that I know that I can make a work around. Thanks for the brainstorm session yall <3.

1 Like