Hi everyone,
i have noticed a possible bug when you have multiple canvases and you try to show the loading screen: there is a single loader and it is misplaced on the top left corner of the page. I thought that would be multiple loading screens on each canvas showing/hiding simultaneously.
I can’t reproduce it on playground due to the single-canvas nature of playground but i’m able to reproduce it on a codesandbox:
The above sandbox is the exact copy of the example from documentation Using Multiple Canvases > Demo with the only adding of engine.displayLoadingUI
method.
Hands on:
The issue could be due to the fact that DefaultLoadingScreen
class relies on the fake canvas this._renderingCanvas
used for the Engine’s initialization. A possibile solution could be to retrieve all canvases associated to the current engine and show/hide the loading screen on each of them.
I have created a pull request that (attempts to) solve the issue:
Tests:
- there are no unit tests because
NullEngine
doesn’t show the loading screen; - i have created two visualization tests (show/hide the loading screen) testing also
_loadingText
and_loadingDivBackgroundColor
properties.
Additional considerations:
- i have used the
onResizeObservable
overresize
listener because a dynamic layout updates the properties of the canvases and so the the loading divs have to be recalculated consequently (you can see the flickering effect also in the above repro sample); - i have preferred a single listener over multiple listeners;
- i have preferred use a map also when there is a single canvas (no multiple views) to ensure a consistent behaviour;
- i thought to the possibility to show/hide a loading screen on a specific canvas (for instance by canvas id), but there shouldn’t be any need because an async operation like asset’s loading or an heavy work, both of them would block the main thread and consequently all canvases.
This is my first pull request, and I’m aware it touches an important part of the project. I’ve tried to approach the issue carefully, but I’m open to any suggestions or improvements. If there are better approaches or changes needed, I’m happy to make adjustments.