-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Audio: Copy filters array in setFilters #20105
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change makes senes. At other places in the engine (e.g. Box3.set()), object arguments are not assigned but copied to the respective target properties, too.
I'd let javascript do its thing: this.filters = value.slice(); // clone array |
If I'm right, mine is more memory efficient than But I know What do you think? If you still prefer |
Yeah, I suspect |
Thanks for the answer. Yeah it would be reasonable. I noticed one more difference between them. const audio = new Audio(listener);
audio.setFilters([audio.context.createGain()]);
const filters = audio.getFilters();
audio.setFilters([]); // Whether should this line have an effect to `filters` or not? Mine reuses The current implementation or Which one should be right behavior do you think? I don't have strong opinion about it. |
Replaced with |
@mrdoob I think this PR is good to go 👍 . |
Thanks! |
Problem this PR fixes
Audio.setFilters()
stores a reference to passed array toAudio.filters
.Then for example in the following example, an operation to
filters
array can have an effect toaudio.filters
even out ofAudio
. I don't think this is expected behavior for users.How this PR fixes
I'd like to suggest copying an array in
Audio.setFilters()
instead of storing a reference. In the above example an operation tofilters
won't have an effect toaudio.filters
. I think it would be better capsulation.