Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/core/lib/validateImageBitmap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function createFakeGl(readbackRed: number, framebufferComplete = true) {
),
deleteFramebuffer: vi.fn(),
deleteTexture: vi.fn(),
// The probe releases its throwaway context via WEBGL_lose_context once done.
getExtension: vi.fn((name: string) =>
name === 'WEBGL_lose_context' ? { loseContext: vi.fn() } : null,
),
};
}

Expand Down Expand Up @@ -116,4 +120,15 @@ describe('detectPremultiplyAlphaHonored', () => {
false,
);
});

it('releases the throwaway context so it does not leak a GL slot', async () => {
const lose = { loseContext: vi.fn() };
const gl = createFakeGl(128);
gl.getExtension = vi.fn((name: string) =>
name === 'WEBGL_lose_context' ? lose : null,
);
await detectPremultiplyAlphaHonored(createPlatform(gl));
expect(gl.getExtension).toHaveBeenCalledWith('WEBGL_lose_context');
expect(lose.loseContext).toHaveBeenCalledTimes(1);
});
});
8 changes: 8 additions & 0 deletions src/core/lib/validateImageBitmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,13 @@ export async function detectPremultiplyAlphaHonored(
gl.deleteTexture(tex);
bitmap.close?.();

// Release this throwaway context immediately. Embedded TV browsers cap the
// number of live WebGL contexts very low; since this probe runs AFTER the
// main render context is created, a leaked context here is the newest one
// and its lingering presence can push the page over the limit, evicting the
// OLDEST context (the live render context) — which then fails every
// createTexture. Don't wait for GC to reclaim the canvas; drop it now.
gl.getExtension('WEBGL_lose_context')?.loseContext();

return result;
}
Loading