Skip to content

Commit b6de5c5

Browse files
committed
Add OffScreenCanvas context lost test
The OffscreenCanvas spec says 'contextlost' not 'webglcontextlost' so ?!?!? but I guess the WebGL spec defines this part.
1 parent 9cacf51 commit b6de5c5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/augment-api.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ export function augmentAPI(ctx, nameOfClass, options = {}) {
170170

171171
if (ctx.canvas) {
172172
ctx.canvas.addEventListener('webglcontextlost', handleContextLost);
173-
ctx.canvas.addEventListener('contextlost', handleContextLost);
174173
ctx.canvas.addEventListener('webglcontextrestored', handleContextRestored);
175-
ctx.canvas.addEventListener('contextrestored', handleContextRestored);
176174
}
177175

178176
resetSharedState();

test/tests/contextloss-tests.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function createExposedPromise() {
1515
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
1616

1717
describe('webgl context loss tests', () => {
18-
it('test context loss', async () => {
19-
const {gl} = createContext();
18+
19+
async function testContextLost(gl) {
2020
const contextLostExposedPromise = createExposedPromise();
2121
const contextRestoredExposedPromise = createExposedPromise();
2222

@@ -104,5 +104,20 @@ describe('webgl context loss tests', () => {
104104

105105
newOESVertexArrayExt.createVertexArrayOES();
106106
assertEqual(memExt.getMemoryInfo().resources.vertexArray, 1);
107+
}
108+
109+
it('test context loss', async () => {
110+
const {gl} = createContext();
111+
await testContextLost(gl);
107112
});
113+
114+
it('test context loss OffscreenCanvas', async () => {
115+
if (typeof OffscreenCanvas === 'undefined') {
116+
return;
117+
}
118+
119+
const gl = new OffscreenCanvas(300, 150).getContext('webgl');
120+
await testContextLost(gl);
121+
});
122+
108123
});

0 commit comments

Comments
 (0)