jnsmalm / pixi3d

The 3D renderer for PixiJS. Seamless integration with 2D applications.
https://pixi3d.org
MIT License
759 stars 44 forks source link

Skybox unable to recover from GL context loss #30

Closed lunarraid closed 2 years ago

lunarraid commented 3 years ago

If the webgl context is lost, the texture for skyboxes becomes non-renderable and throws a multitude of webgl errors. This does not happen for normal meshes. As far as I can tell, this may be an issue with the pixi.js CubeResource, but given your overrides, I wasn't sure if this is necessarily the case. It seems that the textures don't properly upload the second time, because they aren't marked dirty on a context loss?

jnsmalm commented 3 years ago

I actually created an issue at Pixi.js for this https://github.com/pixijs/pixijs/issues/7272 . You can get the same issue by first having a skybox that is visible = true, and then set it to visible = false and wait until Pixi.js has done a GC run, after that the resource is not uploaded correctly if it's set to visible = true again. Might not be possible for you, but one solution might be to disable automatic GC in Pixi.js: https://pixijs.download/dev/docs/PIXI.html#GC_MODES

lunarraid commented 3 years ago

Dang, I even searched through their issues trying to see if this was reported. Thanks for the info! For now I'm just overriding the upload method in my forked branch.

jnsmalm commented 3 years ago

@lunarraid How did you override it? If you have some sort of solution for it, please let me know :)

lunarraid commented 3 years ago

Nothing special, just a really hacky, temporary patch. I copied the CubeResource upload method and turned off the dirty check:

https://github.com/lunarraid/pixi3d/commit/55ee2620474bbccd158390c4824766313d218cc9

jnsmalm commented 3 years ago

How can I force a webgl context to be lost?

lunarraid commented 3 years ago

I did it like this:

    const ext = pixiRenderer.gl.getExtension('WEBGL_lose_context');
    ext.loseContext();
    setTimeout(() => ext.restoreContext(), 100);
lunarraid commented 2 years ago

I just created this PR for PixiJS that resolves this issue for me: https://github.com/pixijs/pixijs/pull/8479

jnsmalm commented 2 years ago

Excellent 👍

lunarraid commented 2 years ago

https://github.com/pixijs/pixijs/pull/8479 landed.