Skip to content

Commit 49bc5ed

Browse files
osamu620claude
andcommitted
fix(wasm): guard invoke_planar_ycbcr_u8 cwrap against stale WASM cache
cwrap for the new export was unconditional, so a stale CDN-cached WASM binary without the export would crash _malloc during module init. Guard with M['_invoke_decoder_planar_ycbcr_u8'] existence check and fall back to invoke_planar_u8 (with CPU MCT) when unavailable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 80a0df6 commit 49bc5ed

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

web/shared/decoder_worker.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ async function init({ wasmBase = '/wasm/', threadCount: tc = 4, output = 'planar
111111
reset_decoder: M.cwrap('reset_decoder_with_bytes','void', ['number','number','number','number']),
112112
parse_j2c: M.cwrap('parse_j2c_data', 'void', ['number']),
113113
invoke_planar_u8: M.cwrap('invoke_decoder_planar_u8','void', ['number','number','number','number']),
114-
invoke_planar_ycbcr_u8: M.cwrap('invoke_decoder_planar_ycbcr_u8','void', ['number','number','number','number']),
114+
invoke_planar_ycbcr_u8: M['_invoke_decoder_planar_ycbcr_u8']
115+
? M.cwrap('invoke_decoder_planar_ycbcr_u8','void', ['number','number','number','number'])
116+
: null,
115117
invoke_to_rgba: M.cwrap('invoke_decoder_to_rgba', 'void', ['number','number']),
116118
apply_bt601: M.cwrap('apply_ycbcr_bt601_to_rgba','void', ['number','number']),
117119
apply_bt709: M.cwrap('apply_ycbcr_bt709_to_rgba','void', ['number','number']),
@@ -281,8 +283,8 @@ function drainReady() {
281283
// Planar path — used by the WebGL2 renderer. Three R8 textures get
282284
// uploaded on main; the fragment shader does the matrix.
283285
// For YCbCr codestreams, skip the CPU color transform and let the GPU
284-
// shader handle YCbCr→RGB conversion — saves ~40% of decode time.
285-
if (isYCbCr)
286+
// shader handle YCbCr→RGB conversion — saves ~29% of decode time.
287+
if (isYCbCr && F.invoke_planar_ycbcr_u8)
286288
F.invoke_planar_ycbcr_u8(decoder, yPtr, cbPtr, crPtr);
287289
else
288290
F.invoke_planar_u8(decoder, yPtr, cbPtr, crPtr);

0 commit comments

Comments
 (0)