Skip to content

[Web] Fix sample playback deletion and AudioStreamPolyphonic issue #108384

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamscott
Copy link
Member

@adamscott adamscott commented Jul 7, 2025

This PR fixes sample playback deletion, as samples were never flagged as deleted.

This also fixes #103311 as samples were marked as active, but never marked as inactive, filling up the polyphonic playback without any way to make space.

Note

A commit will follow to inverse the flow: instead of polling JavaScript to know if a sample is active or not, I'll create a callback for JavaScript to notify Godot directly when a sample was deleted.

Comment on lines +1625 to +1633
LocalVector<Ref<AudioSamplePlayback>> sample_playbacks_to_remove;
for (Ref<AudioSamplePlayback> &sample_playback : sample_playback_list) {
if (!is_sample_playback_active(sample_playback)) {
sample_playbacks_to_remove.push_back(sample_playback);
}
}
for (Ref<AudioSamplePlayback> &sample_playback_to_remove : sample_playbacks_to_remove) {
sample_playback_list.erase(sample_playback_to_remove);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to remove elements from the currently looping for loop list?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just loop with an index instead of range-based for, and start with the last element.

@adamscott adamscott force-pushed the fix-sample-deletion branch from ba3f244 to 6e48c8b Compare July 7, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AudioStreamPolyphonic will not work after a certain number of playback only on the web with PLAYBACK_TYPE_SAMPLE
2 participants