Canvas losing context more and more often

Hey,

I’m using Babylon 4.2.0 btw, Chrome 89.0.4389.82. Hope this is the right place to put this message, I don’t really feel like it’s a Babylon bug.

I’m working on a reasonably big project, so the RAM usage can be like 500MB to 1GB. The GPU usage can be pretty high too. So I’m not surprised that occasionally my project loses context.

But recently I’ve started to see it happen more and more often on my machine, and then after it’s happened a few times Babylon reports that WebGL is not supported. I have to completely close Chrome and open it up again to load the project.

Weirdly when I’m using Firefox I don’t think I’ve seen it happen, certainly not as often. My question is, does anyone have more information on specifically why this could be happening? Is there something we can recommend I can do to limit it happening further? I’ve uploaded a screenshot of my system resource usage while my application is active.

To give a bit more information, we have 3 or 4 videos playing at textures in the world (although I do use Frustum functionality to try to work out if they’re actually in view and pause them if they aren’t). We allow video chatting using Amazon Chime, we have multiplayer with smartfox server, we can potentially have 20-30 skinned meshes animating at the same time.

From my reading the context lost should only happen when the GPU is overloaded, but that doesn’t seem to be the case here. It can happen if I just have 1 browser window open. Also since Chrome doesn’t actually tell you what’s caused it, and it’s quite a recent thing for it getting this bad, I’m really not sure where to start! Has anybody else had this issue?

Annoyingly/maybe positively, my machine seems to be way worse for it than other peoples, even lower spec machines don’t seem to experience it nearly as much.

Capture


Capture-3

EDIT: just noticed the GPU usage is only 9% in that screenshot, it normally hovers around 20% to 30% while the project is running.

Also Babylon doesn’t manage to restore the context on it’s own, which I totally understand. I think I need to put some time into trying to work out how to assist Babylon with this process, but I would prefer it if I could try to reduce the amount of times the context seems to be lost first.

Thank you, apologies for the essay and I’m happy to try to provide more information if there’s anything anyone thinks might be important that I’m missing,
Chris

That should not be the case. We should be able to restore the context as we save everything for it. Can you repro in the Playground?

The cause for context lost could be: out of merory, GPU overload, device change (like when you have 2 gpu)

I’ve written a script to remove context and then restore it. I assume it roughly? simulates what actually happens.

              const ext = webgl2Context.getExtension('WEBGL_lose_context')

                if (ext) {
                  ext.loseContext()
                  setTimeout(function() {
                    console.log('trying to restore context')
                    ext.restoreContext()
                  }, 1000)
                }

scene.render() errors out, if I put it into a try catch it seems to resume correctly after context is restored, but the screen is completely black. Am I missing something obvious?

I will try and make a repro on Monday if there’s nothing completely obvious I’m missing here.

I’m very confused about what could be happening, I wish Chrome could report on this.

Capture-4

Nope that should be it :frowning:
If you can repro in the PG I will make sure to fix the issue if this is in the framework :wink: