WASM backend for tensorflowjs throws "Unhandled Rejection (RuntimeError): index out of bounds" error in Reactjs

I am trying to set up a WASM back-end for blazeface face detection model in a react app. Although the demo with the vanillajs can run it without any error for hours, in react it throws "Unhandled Rejection (RuntimeError): index out of bounds error" after leaving the cam open for more than 3-5 minutes.

Entire app crashes with this error. From the log of the error below, maybe it is related to disposeData() or disposeTensor() functions which to my guess, they are related to garbage collecting. But I don't know if it is a bug from the WASM lib itself or not. Do you have any idea why this might happen?

full log of the error:

Unhandled Rejection (RuntimeError): index out of bounds
(anonymous function)
unknown
./node_modules/@tensorflow/tfjs-backend-wasm/dist/tf-backend-wasm.esm.js/</tt</r</r._dispose_data
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/wasm-out/tfjs-backend-wasm.js:9



disposeData
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/src/backend_wasm.ts:115

  112 | 
  113 | disposeData(dataId: DataId) {
  114 |   const data = this.dataIdMap.get(dataId);
> 115 |   this.wasm._free(data.memoryOffset);
      | ^  116 |   this.wasm.tfjs.disposeData(data.id);
  117 |   this.dataIdMap.delete(dataId);
  118 | }

disposeTensor
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/src/engine.ts:838

  835 |     'tensors');
  836 | let res;
  837 | const inputMap = {};
> 838 | inputs.forEach((input, i) => {
      | ^  839 |     inputMap[i] = input;
  840 | });
  841 | return this.runKernelFunc((_, save) => {

dispose
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/src/tensor.ts:388
endScope
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/src/engine.ts:983
tidy/<
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/src/engine.ts:431

  428 | if (kernel != null) {
  429 |     kernelFunc = () => {
  430 |         const numDataIdsBefore = this.backend.numDataIds();
> 431 |         out = kernel.kernelFunc({ inputs, attrs, backend: this.backend });
      | ^  432 |         const outInfos = Array.isArray(out) ? out : [out];
  433 |         if (this.shouldCheckForMemLeaks()) {
  434 |             this.checkKernelForMemLeak(kernelName, numDataIdsBefore, outInfos);

scopedRun
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/src/engine.ts:448

  445 | // inputsToSave and outputsToSave. Currently this is the set of ops
  446 | // with kernel support in the WASM backend. Once those ops and
  447 | // respective gradients are modularised we can remove this path.
> 448 | if (outputsToSave == null) {
      | ^  449 |     outputsToSave = [];
  450 | }
  451 | const outsToSave = outTensors.filter((_, i) => outputsToSave[i]);

tidy
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/src/engine.ts:431

  428 | if (kernel != null) {
  429 |     kernelFunc = () => {
  430 |         const numDataIdsBefore = this.backend.numDataIds();
> 431 |         out = kernel.kernelFunc({ inputs, attrs, backend: this.backend });
      | ^  432 |         const outInfos = Array.isArray(out) ? out : [out];
  433 |         if (this.shouldCheckForMemLeaks()) {
  434 |             this.checkKernelForMemLeak(kernelName, numDataIdsBefore, outInfos);

tidy
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/src/globals.ts:190

  187 |     const tensors = getTensorsInContainer(container);
  188 |     tensors.forEach(tensor => tensor.dispose());
  189 | }
> 190 | /**
  191 |  * Keeps a `tf.Tensor` generated inside a `tf.tidy` from being disposed
  192 |  * automatically.
  193 |  */

estimateFaces
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/blazeface_reactjs/node_modules/@tensorflow-models/blazeface/dist/blazeface.esm.js:17
Camera/this.renderPrediction
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/blazeface_reactjs/src/Camera.js:148

  145 | const returnTensors = false;
  146 | const flipHorizontal = true;
  147 | const annotateBoxes = true;
> 148 | const predictions = await model.estimateFaces(
      | ^  149 |   this.refVideo.current,
  150 |   returnTensors,
  151 |   flipHorizontal,

async*Camera/this.renderPrediction
C:/Users/osman.cakir/Documents/osmancakirio/deepLearning/blazeface_reactjs/src/Camera.js:399

  396 |         // }
  397 |       }
  398 |     }
> 399 |     requestAnimationFrame(this.renderPrediction);
      | ^  400 |   }
  401 | };
  402 |