Context restored, but errors

Hey!

After some time I have context lost/restored events, but my scene can’t be properly updated

Errors:

In game(icons and text are working because it is HTML layer):

Interesting that purple circles have been built with MeshBuilder, all others objects - my glbs.

Any ideas why others objects can’t be rebuild?

Some notes:

  • I use aggressive optimization + freezeActiveMeshes

Scene:

 this.performancePriority = BABYLON.ScenePerformancePriority.Aggressive;
 this.skipPointerMovePicking = true;
 this.autoClear = false;
 this.skipFrustumClipping = true;
 this.autoClearDepthAndStencil = false;

Engine:

const engine = new Engine(
    canvas,
    false,
    { audioEngine: false, stencil: true, powerPreference: 'low-power', doNotHandleContextLost: true },
    true
  );

// copy pasted from github to solve issue with high-power
// https://github.com/BabylonJS/Babylon.js/pull/13680

  engine._onContextLost = (evt: Event) => {
    evt.preventDefault();
    engine._contextWasLost = true;
    console.warn('WebGL context lost.');
    engine.onContextLostObservable.notifyObservers(engine);
  };

  engine._onContextRestored = () => {
    engine._restoreEngineAfterContextLost(engine._initGLContext.bind(engine));
  };

  canvas.addEventListener('webglcontextlost', engine._onContextLost, false);
  canvas.addEventListener('webglcontextrestored', engine._onContextRestored, false);

I do not think doNotHandleContextLost: true and trying to force it to work will be ok tbh. as doNotHandleContextLost is true, textures/buffers and such do not stay in memory so they can not be recreated after context lost.

2 Likes

Thanks! It is just a temporary solution. Ok, will wait [Bugfix] Respect options.powerPreference without doNotHandleContextLost flag by afrokick · Pull Request #13680 · BabylonJS/Babylon.js · GitHub and now set doNotHandleContextLost = false; again)