Fix: stop media streams in p5.prototype.remove() by calling element.r…#8547
Open
Sanchit2662 wants to merge 1 commit intoprocessing:mainfrom
Open
Fix: stop media streams in p5.prototype.remove() by calling element.r…#8547Sanchit2662 wants to merge 1 commit intoprocessing:mainfrom
Sanchit2662 wants to merge 1 commit intoprocessing:mainfrom
Conversation
…emove() Signed-off-by: Sanchit2662 <sanchit2662@gmail.com>
|
🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors! Thank You! |
Contributor
Author
|
Hi @davepagurek , please review the pr. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
p5.prototype.remove()insrc/core/main.jsmanually removes DOM nodes and event listeners fromthis._elements, but it does not call each element’s ownremove()method.Because of this, the media-specific cleanup inside
p5.Element.prototype.remove()(insrc/dom/dom.js) is skipped. When a sketch usescreateCapture(), callingmySketch.remove()does not stop the underlyinggetUserMediastream. The webcam/microphone remains active and hardware resources are not released.The issue is caused by duplicated cleanup logic in
main.jsthat does not include thep5.MediaElementmedia-stop branch.Fix
The manual DOM + event listener cleanup loop in p5.prototype.remove() has been replaced with calls to each element’s own remove() method.
To avoid mutation issues (since element.remove() splices itself from _elements), iteration is performed over a shallow copy of the array.
By delegating cleanup to p5.Element.prototype.remove():
DOM nodes are removed as before
Event listeners are properly detached
_elements bookkeeping remains correct
Media elements now correctly stop active streams and release hardware devices
This change does not introduce new behavior — it ensures that existing element-level cleanup logic is consistently used during sketch teardown, preventing resource leaks while preserving existing functionality.