Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DrawingUtils constructor failing in Web Workers #5489

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions mediapipe/tasks/web/vision/core/drawing_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ export class DrawingUtils {
cpuOrGpuGontext: CanvasRenderingContext2D|
OffscreenCanvasRenderingContext2D|WebGL2RenderingContext,
gpuContext?: WebGL2RenderingContext) {
if (cpuOrGpuGontext instanceof CanvasRenderingContext2D ||
if ((typeof CanvasRenderingContext2D !== 'undefined' && cpuOrGpuGontext instanceof CanvasRenderingContext2D) ||
cpuOrGpuGontext instanceof OffscreenCanvasRenderingContext2D) {
this.context2d = cpuOrGpuGontext;
this.contextWebGL = gpuContext;
} else {
// If the first `if` statement is false, then the first argument must be a
// WebGL2RenderingContext, since CanvasRenderingContext2D can't
// be passed as the first argument. However, typescript isn't
// smart enough to infer this, so we need to use @ts-ignore.
// @ts-ignore
this.contextWebGL = cpuOrGpuGontext;
}
}
Expand Down Expand Up @@ -511,5 +516,3 @@ export class DrawingUtils {
this.convertToWebGLTextureShaderContext = undefined;
}
}