Fix a crash that occurred when a model returns fewer vector elements than before

PiperOrigin-RevId: 489041814
This commit is contained in:
Sebastian Schmidt 2022-11-16 14:36:14 -08:00 committed by Copybara-Service
parent 74474d859e
commit 3cdf0f6536

View File

@ -406,7 +406,7 @@ export class WasmMediaPipeLib {
*/
setVectorListener<T>(
outputStreamName: string, callbackFcn: (data: T[]) => void) {
const buffer: T[] = [];
let buffer: T[] = [];
this.wasmModule.vectorListeners = this.wasmModule.vectorListeners || {};
this.wasmModule.vectorListeners[outputStreamName] =
(data: unknown, index: number, length: number) => {
@ -419,6 +419,7 @@ export class WasmMediaPipeLib {
// the underlying data elements once we leave the scope of the
// listener.
callbackFcn(buffer);
buffer = [];
}
};
}