Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(render): a restored WebGL context is given its extensions again before the device probes what it can do

yhh8270b23db2c5
diff --git a/src/esengine/renderer/rhi/GLDevice.cpp b/src/esengine/renderer/rhi/GLDevice.cpp
index ec9237b53..9c88b5714 100644
--- a/src/esengine/renderer/rhi/GLDevice.cpp
+++ b/src/esengine/renderer/rhi/GLDevice.cpp
@@ -19,6 +19,7 @@
#include <emscripten/html5.h>
#endif
+#include <cstdlib>
#include <cstring>
#ifndef GL_DEPTH_STENCIL
@@ -398,6 +399,20 @@ bool GLDevice::recreateDevice() {
// handle, and until it does there is nothing to do but wait.
const EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();
if (ctx == 0 || emscripten_is_webgl_context_lost(ctx)) return false;
+ // A restored context has no extension enabled, and the probes in init() read what is SUPPORTED: the float targets of an HDR
+ // frame would be judged renderable and every one of them come back incomplete. The hosts register the context with every
+ // extension enabled (enableExtensionsByDefault), so the restored one is given them all again first.
+ if (char* names = emscripten_webgl_get_supported_extensions()) {
+ for (char* name = names; *name;) {
+ char* end = name;
+ while (*end && *end != ' ') ++end;
+ const char next = *end;
+ *end = '\0';
+ if (end != name) emscripten_webgl_enable_extension(ctx, name);
+ name = next ? end + 1 : end;
+ }
+ free(names);
+ }
#endif
// Every name belonged to the old context. The registry rebuilds each object
// behind its id; nothing here survives but the maps' shape.
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 1ccd4b950..e0583a24e 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -895,6 +895,8 @@ export const SCENES = [
{ id: "device-roundtrip-morph-material", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/mesh-morph-mat.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },
{ id: "device-roundtrip-shadow-material", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/mesh-shadow-material.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },
{ id: "device-roundtrip-sky", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/mesh-sky.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },
+ // A restored WebGL context has no extension enabled: unless the engine enables them again, the float targets of an HDR chain come back incomplete and the frame is black.
+ { id: "device-roundtrip-hdr-bloom", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_PLAY: "1", ESTELLA_VERIFY_COLORSPACE: "linear", ESTELLA_VERIFY_SCENE: "/scenes/hdr-bloom.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/hdr-bloom.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10" } },
{ id: "device-roundtrip-env", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/mat-env.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },
{ id: "device-roundtrip-light-cookie", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_DEVICE_LOSS: "roundtrip", ESTELLA_VERIFY_LOSS_ROUNDS: "2", ESTELLA_VERIFY_SCENE: "/scenes/light-cookie.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/light-cookie.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "3" } },
// A glyph page and a skeleton's atlas page come back from what made them, not from a copy: