Skip to content

Commit 1d5a587

Browse files
committed
fix: proxy stub for makeRenderImage when WebGL unavailable on headless Linux
1 parent 237c9fb commit 1d5a587

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

scripts/rive-extract-schema.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,28 @@ async function main() {
6060
const bytes = await loadBytes(source);
6161
const runtime = await RuntimeLoader.awaitInstance();
6262

63-
// Stub image loading: call la() (the "loaded" callback) immediately so
64-
// runtime.load() resolves without waiting for CDN asset fetches.
65-
// Guard against null return when WebGL is unavailable (headless Linux).
66-
const origMRI = (runtime.renderFactory as any).makeRenderImage.bind(
63+
// Stub makeRenderImage so runtime.load() resolves even without WebGL.
64+
// On headless Linux, origMRI() returns null (no GPU), and passing null back
65+
// causes the WASM to call process.exit(0) silently. Return a Proxy stub that
66+
// no-ops all method calls and immediately fires the "loaded" callback (la).
67+
const origMRI = (runtime.renderFactory as any).makeRenderImage?.bind(
6768
runtime.renderFactory
6869
);
69-
(runtime.renderFactory as any).makeRenderImage = function () {
70-
const img = origMRI();
71-
if (img) queueMicrotask(() => img.la?.());
72-
return img;
73-
};
70+
if (origMRI) {
71+
(runtime.renderFactory as any).makeRenderImage = function () {
72+
const img = origMRI();
73+
if (img) {
74+
queueMicrotask(() => img.la?.());
75+
return img;
76+
}
77+
// No WebGL: proxy that no-ops all calls so the WASM doesn't crash
78+
const stub: any = new Proxy(Object.create(null), {
79+
get: (_t, _p) => () => {},
80+
});
81+
queueMicrotask(() => stub.la());
82+
return stub;
83+
};
84+
}
7485

7586
const riveFile = await runtime.load(bytes, undefined, false);
7687

0 commit comments

Comments
 (0)