mediapipe: wasm: abort Runtime bug in FaceMesh on javascript in Chrome
Chrome: 96.0.4664.110 “node”: “14.15.4”, “npm”: “6.14.x” React: 16.13.1
perhaps there is some garbage collection that I can do to ‘reset’/clear the connection?
RuntimeError: abort(Module.arguments has been replaced with plain arguments_ (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)) at Error
at jsStackTrace (https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh_solution_simd_wasm_bin.js:9:69351)
at stackTrace (https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh_solution_simd_wasm_bin.js:9:69527)
at abort (https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh_solution_simd_wasm_bin.js:9:43094)
at Object.get (https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh_solution_simd_wasm_bin.js:9:24082)
at https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh_solution_simd_wasm_bin.js:9:23905
at pa.h (https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js:53:414)
at sa (https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js:14:299)
at ta.next (https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js:15:91)
at https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js:42:1377
at new Promise (<anonymous>)
at Z (https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js:42:1147)
at https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js:53:254
at async Promise.all (index 0)
from this code:
const MediaPipeVisualiser = (params) => {
const {
mode,
maskedParticipant,
} = params;
const maskParticipant = async (
mode: string,
maskedParticipant: Array
) => {
try {
canvasName = <yourcanvasname>
videoEl = <yourvideoelementid>
canvasOverlayBuff = document.querySelector(
`#${canvasName}`
) as HTMLCanvasElement;
cOverlay = canvasOverlayBuff.getContext("2d");
videoEl = document.querySelector(
`#${videoElementName}`
) as HTMLCanvasElement;
} catch (e) {
console.log("error in mediapipe vis");
}
};
useEffect(() => {
if (faceMesh == null || faceMesh == undefined) {
faceMesh = new FaceMesh({
locateFile: (file) => {
return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`;
},
});
faceMesh.setOptions({
maxNumFaces: 1,
refineLandmarks: true,
minDetectionConfidence: 0.5,
minTrackingConfidence: 0.5,
});
}
faceMesh.onResults(onResults);
if (videoEl !== null) {
camera = new Camera(videoEl, {
onFrame: async () => {
await faceMesh.send({ image: videoEl });
},
width: 1280,
height: 720,
});
camera.start();
}
return () => {
// try to resolve abort/cache issue but doesn't help
faceMesh = null;
// if (camera) camera.stop(); --interferes with camera function
videoEl = null;
};
}, [videoEl, maskedParticipant]);
return <div />;
};
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18
EDIT: SEE MY REPLY BELOW FOR CORRECTION OF MASSIVE TYPO. But basically, a hacky workaround in react is to NOT use React.StrictMode
There seems to be a number of people experiencing a similar style of issue to this. I’m developing custom code using the Hands and DrawingUtils modules from MediaPipe. I am using react / JS. I experienced a very similar message. The message would appear most of the time, but there would be times when the error would go away. The code I was using, is very standard and similar to that provided in the docs. I actually found that React was causing the issue (or rather, a react setting could provide a sloppy workaround for the issue). I was testing my code in dev mode (using npm start). However, by default, React uses strict mode when in dev mode. Amongst other things, this means that each component is rendered twice. So in order to mitigate this, I added a flag that made it so that useEffect would only run once. This fixed my errors. However, it was a nightmare to maintain and I don’t think only running the code once can guarantee no errors for all use cases. Ultimately, I simply edited my react app so that it wouldn’t run in strict mode. This fixed the issues that produced error messages similar to what you and others have described. It is a workaround and a poor one (as strict mode has a lot of useful dev features). However, if you want a quick fix, it’s worth a try. So my index.js file went from roughly:
`import React from ‘react’; import ReactDOM from ‘react-dom/client’; import ‘./index.css’; import App from ‘./App’; import reportWebVitals from ‘./reportWebVitals’;
const root = ReactDOM.createRoot(document.getElementById(‘root’)); root.render( <App /> ); reportWebVitals();`
TO:
`import React from ‘react’; import ReactDOM from ‘react-dom/client’; import ‘./index.css’; import App from ‘./App’; import reportWebVitals from ‘./reportWebVitals’;
const root = ReactDOM.createRoot(document.getElementById(‘root’)); root.render( <React.StrictMode> <App /> </React.StrictMode> ); reportWebVitals();`
Hope this helps in some way. Though, this still wouldn’t explain why the codepen demo doesn’t work. I’ve attached the working version of my project in case you want to have a deeper look at my code. Good luck! project.zip
DON’T Delete the React.StrictMode. We want this there to check if we run into some strange states, effects or callbacks. Which it seems like we do with the mediapipe, the problem seems to be when you trying to setOptions or intialize the same face detection twice (which is bad practice). However we can solve this by saving the current faceDetection and don’t do these calls if it is already setup.
I solved it like this:
You could also ofcourse do .stop() threw it away and start up a new FaceDetection if you rather want that.