fix(web): fix Android Chrome black screen and Fixed-mode WebGL2 viewport scissor

Resolves the Android Chrome black screen after closing the welcome back interface and prevents Fixed-mode 317HD `gl.clear` from wiping surrounding HUD/border regions.

### WebGL2 Context & Fixed-Mode Scissoring
- `WebGL2.java`:
  - Enabled `preserveDrawingBuffer: true` and removed `desynchronized: true` on the `#gl-canvas` WebGL2 context to prevent Android Chrome from clearing or failing to composite between frames.
  - Added `SCISSOR_TEST` (`0x0C11`) and `scissor(x, y, width, height)` bindings.
- `WebHd317Renderer.java`:
  - Wrapped Pass 2 (`gl.clear` and 3D scene draw) in `GL_SCISSOR_TEST` (`gl.scissor(vpX, vpY, width, height)`) so Fixed-mode stone borders, chatbox, and tab areas are preserved.
  - Reused `HD317Pipeline.backend` in `ensureOverlayReady()` to avoid creating duplicate `WebHd317Renderer` instances.
- `RSImageProducer.java`:
  - Removed `desynchronized: true` from `#game-canvas`'s 2D context so Android Chrome composites `#game-canvas` transparently over `#gl-canvas`.

### Service Worker Caching
- `src/main/webapp/sw.js`:
  - Bumped `CACHE_VERSION` to `2006scape-web-v3` and switched `js/client.js` to network-first (with cache fallback) so client updates take effect immediately when online.
This commit is contained in:
Dark98 committed 2026-11-30 22:41:05 +00:00
1 parent ededb882a0
commit 4bcb91c3a2
4 files changed
+19 -7

No files matched your search

@@ -55,7 +55,7 @@ public final class RSImageProducer {
}
@JSBody(params = {"canvas"}, script =
"try { return canvas.getContext('2d', { alpha: true, desynchronized: true }) || canvas.getContext('2d'); }\n" +
"try { return canvas.getContext('2d', { alpha: true }) || canvas.getContext('2d'); }\n" +
"catch (_) { return canvas.getContext('2d'); }")
private static native CanvasRenderingContext2D create2dContext(HTMLCanvasElement canvas);
+3 -1
View File
@@ -20,6 +20,7 @@ public interface WebGL2 extends JSObject {
int SRC_ALPHA = 0x0302;
int ONE_MINUS_SRC_ALPHA = 0x0303;
int DEPTH_TEST = 0x0B71;
int SCISSOR_TEST = 0x0C11;
int BLEND = 0x0BE2;
int POLYGON_OFFSET_FILL = 0x8037;
int FLOAT = 0x1406;
@@ -65,12 +66,13 @@ public interface WebGL2 extends JSObject {
interface UniformLocation extends JSObject {}
@JSBody(params = {"canvas"}, script =
"return canvas.getContext('webgl2', { alpha: false, antialias: false, preserveDrawingBuffer: false, powerPreference: 'high-performance', desynchronized: true });")
"return canvas.getContext('webgl2', { alpha: false, antialias: false, preserveDrawingBuffer: true, powerPreference: 'high-performance' });")
static WebGL2 getContext(HTMLCanvasElement canvas) {
return null;
}
void viewport(int x, int y, int width, int height);
void scissor(int x, int y, int width, int height);
void clearColor(float r, float g, float b, float a);
void clear(int mask);
void enable(int cap);
@@ -358,6 +358,8 @@ public final class WebHd317Renderer implements HD317Pipeline.HdRendererBackend {
int vpY = ClientSettings.isDesktopModern() ? 0 : Math.max(0, canvasH - 4 - height);
gl.bindFramebuffer(WebGL2.FRAMEBUFFER, null);
gl.viewport(vpX, vpY, width, height);
gl.enable(WebGL2.SCISSOR_TEST);
gl.scissor(vpX, vpY, width, height);
gl.clearColor(fogColor[0], fogColor[1], fogColor[2], 1.0f);
gl.clear(WebGL2.COLOR_BUFFER_BIT | WebGL2.DEPTH_BUFFER_BIT);
gl.enable(WebGL2.DEPTH_TEST);
@@ -466,6 +468,7 @@ public final class WebHd317Renderer implements HD317Pipeline.HdRendererBackend {
unbindSceneVertexAttribs();
}
gl.disable(WebGL2.SCISSOR_TEST);
if (!loggedFirstFrame) {
loggedFirstFrame = true;
@@ -711,7 +714,14 @@ public final class WebHd317Renderer implements HD317Pipeline.HdRendererBackend {
public static boolean ensureOverlayReady() {
if (isOverlayReady()) return true;
if (instance == null) {
new WebHd317Renderer();
if (HD317Pipeline.backend instanceof WebHd317Renderer) {
instance = (WebHd317Renderer) HD317Pipeline.backend;
} else {
instance = new WebHd317Renderer();
if (HD317Pipeline.backend == null) {
HD317Pipeline.backend = instance;
}
}
}
return instance.ensureOverlayContext();
}
+4 -4
View File
@@ -1,4 +1,4 @@
const CACHE_VERSION = '2006scape-web-v1';
const CACHE_VERSION = '2006scape-web-v3';
const SHELL_ASSETS = [
'./',
'index.html',
@@ -48,7 +48,7 @@ self.addEventListener('fetch', (event) => {
const url = new URL(req.url);
if (url.origin !== self.location.origin) return;
if (req.mode === 'navigate' || url.pathname.endsWith('/index.html') || url.pathname === '/') {
if (req.mode === 'navigate' || url.pathname.endsWith('/index.html') || url.pathname === '/' || url.pathname.endsWith('/js/client.js')) {
event.respondWith((async () => {
try {
const fresh = await fetch(req);
@@ -59,13 +59,13 @@ self.addEventListener('fetch', (event) => {
return fresh;
} catch (_) {
const cached = await caches.match(req);
return cached || caches.match('index.html');
return cached || (req.mode === 'navigate' ? caches.match('index.html') : Response.error());
}
})());
return;
}
if (/\.(js|png|gif|jpg|jpeg|webp|svg|ico|css|webmanifest|dat|idx\d*)$/i.test(url.pathname)) {
if (/\.(png|gif|jpg|jpeg|webp|svg|ico|css|webmanifest|dat|idx\d*)$/i.test(url.pathname)) {
event.respondWith((async () => {
const cache = await caches.open(CACHE_VERSION);
const cached = await cache.match(req);