Skip to content

fix(export): default Lightning renderer to WebGL to avoid Pixi batch crash on Linux - #1012

Open
swadhinbiswas wants to merge 1 commit into
webadderallorg:mainfrom
swadhinbiswas:fix/lightning-webgl-default-948
Open

swadhinbiswas wants to merge 1 commit into
webadderallorg:mainfrom
swadhinbiswas:fix/lightning-webgl-default-948

Conversation

@swadhinbiswas

@swadhinbiswas swadhinbiswas commented Sep 22, 2026 •

Copy link
Copy Markdown

Description

Default the Lightning (Beta) / modern export renderer to WebGL-first when no render backend is explicitly requested. WebGPU remains the fallback.

Motivation

Lightning exports crash on Linux (e.g. Arch + Mesa) on the first frame with:

Cannot read properties of undefined (reading '_resourceType')

(#948, #644)

Root cause: pixi.js 8.14's DefaultBatcher caches a single module-level batch shader sized by the texture limit of the first renderer created in the page, and never regenerates it:

let defaultShader = null;
defaultShader ??= new DefaultShader(options.maxTextures); // first renderer wins, forever

The editor preview initializes WebGL first. On Mesa drivers WebGL exposes 32 texture units, while WebGPU exposes 16 (maxSampledTexturesPerShaderStage). The modern export renderer passed preferredRenderBackend: undefined and treated "auto" as WebGPU-first, so it reused a bind group layout expecting 32 textures while its batch bind group only supplied 16. BindGroupSystem._createBindGroup then read an undefined resource and threw. On macOS/Windows both backends report 16 (ANGLE), which is why only Linux is affected.

Both the legacy frame renderer (src/lib/exporter/frameRenderer.ts) and the editor preview already default to WebGL-first, and getDefaultLightningRenderBackend() returns "webgl" (currently unused). This change makes the modern renderer consistent with them, so the export always shares the same backend family — and therefore the same batch texture limit — as the preview.

Note: this is an alternative, root-cause fix to #951. #951 keeps WebGPU-first and falls back to WebGL after detecting the limit mismatch at runtime; this change avoids constructing the incompatible renderer in the first place and keeps all backend-selection paths consistent.

Type of Change

  • Bug Fix

Related Issue(s)

Fixes #948, fixes #644. Alternative to #951.

Screenshots / Video

Not applicable — backend-selection change, no UI change.

Testing Guide

  1. New regression test (fails before the fix, passes after): npx vitest --run src/lib/exporter/modernFrameRenderer.test.ts — with no explicit backend and WebGPU available, the first renderer init uses preference: "webgl".
  2. Full suite: npm ci --ignore-scripts && npm rebuild ffmpeg-static && npm test (1346 tests).
  3. npx tsc --noEmit and npm run lint.
  4. On Linux with Mesa, run a Lightning export: it now initializes WebGL and completes via WebCodecs.

Checklist

  • I have performed a self-review of my code.
  • I have added any necessary screenshots or videos. (N/A)
  • I have linked related issue(s) and updated the changelog if applicable.

Summary by CodeRabbit

  • Bug Fixes
    • Improved export rendering compatibility by using WebGL by default, matching the editor preview.
    • WebGPU remains available when explicitly selected, with WebGL as a fallback.
    • Resolved potential rendering issues on systems using Mesa graphics drivers.

…crash

Pixi caches a single module-level batch shader (`DefaultBatcher`'s
`defaultShader`) sized by the texture limit of the first renderer created in the
page, and pixi.js 8.14 never regenerates it. The editor preview initializes
WebGL first; on Mesa drivers WebGL exposes 32 texture units while WebGPU
exposes 16, so the modern export renderer reused a bind group layout that
expected 32 textures but only had 16 and crashed on the first frame with
"Cannot read properties of undefined (reading '_resourceType')".

Default the Lightning (modern) export renderer to WebGL-first, keeping WebGPU
as the fallback. This matches the editor preview, the legacy frame renderer, and
getDefaultLightningRenderBackend(), so the export always shares the same
backend family (and therefore the same batch texture limit) as the preview.

Fixes webadderallorg#948
Fixes webadderallorg#644
@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: webadderallorg/Recordly/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 8906a051-d24a-491d-9a7a-51eb88f84b5d

📥 Commits

Reviewing files that changed from the base of the PR and between 6cdd223 and 3e29077.

📒 Files selected for processing (2)
  • src/lib/exporter/modernFrameRenderer.test.ts
  • src/lib/exporter/modernFrameRenderer.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The exporter now attempts WebGL first when no backend is specified. An explicit WebGPU preference still uses WebGPU first with WebGL fallback. Tests record Pixi initialization options and verify the default WebGL path.

Changes

Exporter backend selection

Layer / File(s) Summary
WebGL-first backend selection and validation
src/lib/exporter/modernFrameRenderer.ts, src/lib/exporter/modernFrameRenderer.test.ts
createPixiApplication now uses WebGL first unless preferredRenderBackend is "webgpu". The tests record Pixi initialization options and verify one WebGL instance for the default path.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: webadderall

Merge Risk: ⚪ Minimal · up to 3e290

Exports without an explicit backend now prefer WebGL while preserving explicit WebGPU support and fallback behavior. The covered change is merge-ready with no actionable blocking risk identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: making the Lightning export renderer default to WebGL to prevent a Pixi batch crash on Linux.
Description check ✅ Passed The description is complete and covers the change, motivation, technical root cause, bug-fix classification, related issues, testing steps, and checklist. It correctly marks screenshots as not applica…
Linked Issues check ✅ Passed The change addresses [#948] and [#644] by selecting WebGL first when preferredRenderBackend is unset. WebGPU remains available as the fallback and remains selectable when explicitly requested. This …
Out of Scope Changes check ✅ Passed The pull request changes only src/lib/exporter/modernFrameRenderer.ts and its regression test. The implementation changes Lightning backend selection, and the test verifies the required automatic-se…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@swadhinbiswas

Copy link
Copy Markdown
Author
image

@Masud744

Copy link
Copy Markdown

Linux Testing Verification Report

I tested this PR on Linux x64 (AppImage v1.4.0) and can confirm that this fix completely resolves the export crash issue!

Before (on v1.4.0):

  • Export failed immediately when defaulting to WebGPU:

    Cannot read properties of undefined (reading '_resourceType')
    Platform: Linux | Renderer: webgpu

Screenshot From 2026-09-25 02-31-57 After (with this patch applied): - Export defaulted gracefully to **WebGL (`Path: WebGL + WebCodecs`)**. - The export is buttery smooth, running at **~124.6 FPS** with zero crashes.

Attached is the live export screenshot. Highly recommend merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants