Skip to content

Commit 98160e5

Browse files
committed
Fix: use instance renderer in p5.MediaElement.loadPixels to support module contexts
1 parent 8b260bb commit 98160e5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/dom/dom.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4956,10 +4956,21 @@ class MediaElement extends p5.Element {
49564956
this._frameOnCanvas = this._pInst.frameCount;
49574957
}
49584958
}
4959-
loadPixels(...args) {
4960-
this._ensureCanvas();
4959+
loadPixels(...args) {
4960+
this._ensureCanvas();
4961+
4962+
// ✅ use the current p5 instance’s renderer instead of global p5
4963+
if (this._pInst && this._pInst._renderer) {
4964+
return this._pInst._renderer.loadPixels(...args);
4965+
}
4966+
4967+
// fallback for old global mode (just in case)
4968+
if (typeof p5 !== 'undefined' && p5.Renderer2D && p5.Renderer2D.prototype) {
49614969
return p5.Renderer2D.prototype.loadPixels.apply(this, args);
49624970
}
4971+
4972+
throw new Error('p5 instance or renderer not available in MediaElement.loadPixels()');
4973+
}
49634974
updatePixels(x, y, w, h) {
49644975
if (this.loadedmetadata) {
49654976
// wait for metadata

0 commit comments

Comments
 (0)