Skip to content

Commit 53a5ac3

Browse files
authored
fix: handle async errors in background filters pipeline (#1571)
Our background filters pipeline has an async part that runs out of band with the rest of the pipeline. Errors originating in this async part (like #1565) were not properly handled, didn't invoke the `onError` callback, and caused unhandled rejection errors in the console. This PR fixes these issues.
1 parent d0a0b24 commit 53a5ac3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/video-filters-web/src/webgl2/resizingStage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function buildResizingStage(
1515
texCoordBuffer: WebGLBuffer,
1616
tflite: TFLite,
1717
segmentationConfig: SegmentationParams,
18+
onError?: (error: any) => void,
1819
) {
1920
const fragmentShaderSource = glsl`#version 300 es
2021
@@ -81,7 +82,9 @@ export function buildResizingStage(
8182
gl.RGBA,
8283
gl.UNSIGNED_BYTE,
8384
outputPixels,
84-
);
85+
).catch((error: any) => {
86+
onError?.(error);
87+
});
8588

8689
for (let i = 0; i < outputPixelCount; i++) {
8790
const tfliteIndex = tfliteInputMemoryOffset + i * 3;

packages/video-filters-web/src/webgl2/webgl2Pipeline.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function buildWebGL2Pipeline(
2222
canvas: HTMLCanvasElement,
2323
tflite: TFLite,
2424
segmentationConfig: SegmentationParams,
25+
onError?: (error: any) => void,
2526
) {
2627
const gl = canvas.getContext('webgl2')!;
2728
if (!gl) throw new Error('WebGL2 is not supported');
@@ -95,6 +96,7 @@ export function buildWebGL2Pipeline(
9596
texCoordBuffer,
9697
tflite,
9798
segmentationConfig,
99+
onError,
98100
);
99101
const loadSegmentationStage = buildSoftmaxStage(
100102
gl,

0 commit comments

Comments
 (0)