In a Nextjs project, when I tried to initialize deepar as soon as the page and everything loaded, it works.
const loadDeepAr = async () => {
if(canvasRef.current && !deepArRef.current){
const deepAR = await deepar.initialize({
licenseKey: `${process.env.NEXT_PUBLIC_DEEPAR_KEY}`,
canvas: canvasRef.current,
effect: deepArEffects.viking_helmet,
additionalOptions: {
cameraConfig: {
disableDefaultCamera: true
}
}
});
deepArRef.current = deepAR
deepArRef.current.setVideoElement(videoEl.current!, mirrored)
}
}
useEffect(() => {
if(canvasRef.current && !deepArRef.current){
loadDeepAr()
}
}, [canvasRef.current, deepArRef.current])
But, as soon as It was created as a toggle, it breaks with
Aborted()
and
RuntimeError: unreachable executed
Vb deepar.esm.js:2
Ub deepar.esm.js:2
ny deepar.esm.js:2
I’m at lost
const toggleDeepAr = () => {
if(!!canvasRef.current){
if(!deepArRef.current && enabledTracking){
deepar.initialize({
licenseKey: `${process.env.NEXT_PUBLIC_DEEPAR_KEY}`,
canvas: canvasRef.current,
effect: deepArEffects.Fire_Effect,
additionalOptions: {
cameraConfig: {
disableDefaultCamera: true
}
},
})
.then((result) => {
deepArRef.current = result
deepArRef.current.setVideoElement(videoEl.current!, mirrored)
})
.catch((err: any) => {
console.log(err);
addToast({ type: 'error', message: err?.message ?? 'Failed to init deepAr' })
})
} else {
deepArRef.current = undefined
}
}
}
useEffect(() => {
toggleDeepAr()
}, [canvasRef.current, deepArRef.current, enabledTracking, videoEl])
The trigger being enabledTracking state.
I can see in the network that .deepar file (selected effect) and deepar wasm fetched successfully, but dyXzimgMagicFace.wasm and models-68-extreme.bin are missing.
And also, how do you cleanup the process as cleaning the ref isn’t dong anything
Error: deepar.initialize() called but DeepAR is currently being initialized.
shows up when It get called again