Skip to content

Commit 78d7cf8

Browse files
authored
Merge pull request #4957 from KKVANONYMOUS/main
Fix 'this.elt.srcObject is null' error
2 parents 13ef5bd + b20d0f8 commit 78d7cf8

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+
const sources = this.elt.srcObject;
2178+
if (sources !== null) {
2179+
const 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)