Skip to content

Commit 7da1cc2

Browse files
committed
Fix 'this.elt.srcObject is null' error
1 parent 13ef5bd commit 7da1cc2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/dom/dom.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,10 +2173,14 @@ p5.Element.prototype.remove = function() {
21732173
// stop all audios/videos and detach all devices like microphone/camera etc
21742174
// used as input/output for audios/videos.
21752175
if (this instanceof p5.MediaElement) {
2176-
const tracks = this.elt.srcObject.getTracks();
2177-
tracks.forEach(function(track) {
2178-
track.stop();
2179-
});
2176+
this.stop();
2177+
let sources = this.elt.srcObject;
2178+
if (sources !== null) {
2179+
let tracks = sources.getTracks();
2180+
tracks.forEach(track => {
2181+
track.stop();
2182+
});
2183+
}
21802184
}
21812185

21822186
// delete the reference in this._pInst._elements

0 commit comments

Comments
 (0)