ml5-next-gen icon indicating copy to clipboard operation
ml5-next-gen copied to clipboard

`bodyPose` and `bodySegmentation` failing to preload in p5 instance mode

Open jackbdu opened this issue 1 year ago • 3 comments

Creating a new issue to track the progress of this:

@lindapaiste Thank you for adding support for instance mode. I was able to preload most models (ml5.faceMesh, ml5.handPose, ml5.imageClassifier, ml5.neuralNetwork, and ml5.sentiment) but I'm getting an error for ml5.bodyPose. See this minimal sketch demonstrating the issue. I also included my temporary fix in the comments, which creates blank window._incrementPreload() and window._decrementPreload() to avoid this error.

I'm also getting an error for preloading ml5.bodySegmentation in instance mode, and that could be fixed by declaring a global variable let video;.

Originally posted by @jackbdu in https://github.com/ml5js/ml5-next-gen/issues/81#issuecomment-2067780151

jackbdu avatar Jul 22 '24 18:07 jackbdu

We need to remove this call: https://github.com/ml5js/ml5-next-gen/blob/542e5a5171a428e807451ca901cc130b54d6f8e9/src/BodyPose/index.js#L56 (and any others like it)

There will be no window._incrementPreload when using instance mode because _incrementPreload will be a property of the p5 instance, rather than a property of the window.

lindapaiste avatar Jul 22 '24 19:07 lindapaiste

I'm also getting an error for preloading ml5.bodySegmentation in instance mode, and that could be fixed by declaring a global variable let video;.

Likely we have some code that is using an improperly scoped video variable. We definitely should not have a global/window scoped video variable anywhere. I suspect it's an issue where we are using this.video in a context where this is actually the window. That sort of thing can be fixed by binding the function to the correct this context. I would need to dig into the code to find where the bad variable is.

lindapaiste avatar Jul 22 '24 19:07 lindapaiste

We're using a variable video that doesn't exist on like 34 of BodySegmentation.

https://github.com/ml5js/ml5-next-gen/blob/84419b3d2808aac1a6214c24f1f6b00d918127f2/src/BodySegmentation/index.js#L34

lindapaiste avatar Aug 06 '24 20:08 lindapaiste

I don't believe this is an issue anymore, I tested the example linked in the original comment with the latest release and there is no error. If I am mistaken I will be glad to re-open. Also, while we will continue to support preload we are moving to p5.js 2.0 async and await model.

shiffman avatar Jul 30 '25 02:07 shiffman