Skip to content

Commit b9066c1

Browse files
committed
ix a Type Error exception with the latest version of Safari when using OffscreenCanvas element as a texture source
- `textImage2D()` won't accept a OffscreenCanvas directly as a texture source - disable internal use of OffscreenCanvas when drawing font (for now), as with the above changes it produces weird artefacts
1 parent c88d51b commit b9066c1

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
### Fixed
1414
- Renderer: add missing export for the `CanvasTexture` class
15+
- WebGL: fix a Type Error exception with the latest version of Safari when using OffscreenCanvas element as a texture source
1516

1617
## [15.0.0] (melonJS 2) - _2023-03-18_
1718

‎src/text/text.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ const toPX = [12, 24, 0.75, 1];
169169
}
170170

171171
// the canvas Texture used to render this text
172-
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
172+
// XXX: offscreenCanvas is currently disabled for text rendering due to issue in WebGL mode
173+
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: false });
173174

174175
// instance to text metrics functions
175176
this.metrics = new TextMetrics(this);

‎src/video/webgl/compositors/quad_compositor.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ var V_ARRAY = [
9090
if (pixels === null || typeof pixels.byteLength !== "undefined") {
9191
// if pixels is undefined, or if it's Uint8Array/Float32Array TypedArray
9292
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels, 0);
93+
} else if (pixels instanceof OffscreenCanvas) {
94+
// convert to ImageBitmap first (else Safari 16.4 and higher will throw an TypeError exception)
95+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels.transferToImageBitmap());
9396
} else {
9497
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
9598
}

0 commit comments

Comments
 (0)