vladmandic / face-api

FaceAPI: AI-powered Face Detection & Rotation Tracking, Face Description & Recognition, Age & Gender & Emotion Prediction for Browser and NodeJS using TensorFlow/JS
https://vladmandic.github.io/face-api/demo/webcam.html
MIT License
824 stars 149 forks source link

Detached EventHandlers when running on a Canvas #187

Closed rebser closed 7 months ago

rebser commented 7 months ago

Issue Description

When running on a Canvas, EventHandlers are leaking.

Steps to Reproduce

Just run for example tinyFaceDetector on a Canvas.

Expected Behavior

face-api should not produce Detached EventHandlers

**Environment

Browser

rebser commented 7 months ago

Turns out the bug is in awaitMediaLoaded.

if (media instanceof env.getEnv().Canvas || isMediaLoaded(media)) resolve(null); doesn't do the trick because it resolves the Promise to null but doesn't return, meaning the EventHandlers for load and error are still being added.

Solution: if (media instanceof env.getEnv().Canvas || isMediaLoaded(media)) { resolve(null); return; }

vladmandic commented 7 months ago

great job tracing it down - do you wan to submit a pr or do you want me to patch it?

rebser commented 7 months ago

Edit: I created a pull request.