Skip to content
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

Server: avoid re-use of recent ParticleSpawner and Sound IDs #14045

Merged
merged 2 commits into from Nov 29, 2023

Conversation

SmallJoker
Copy link
Member

This improves the reliability when removing and re-adding handles quickly. Looping through the entire ID range avoids collisions caused by any race condition.

Fixes #14044

To do

This PR is Ready for Review.

How to test

  1. ParticleSpawner (and maybe sound) IDs Reused #14044 -> "Steps to reproduce"

This improves the reliability when removing and re-adding handles quickly.
Looping through the entire ID range avoids collisions caused by any race condition.
u32 free_id = m_particle_spawners_id_last_used;
while (free_id == 0 || m_particle_spawners.find(free_id) != m_particle_spawners.end()) {
if (free_id == m_particle_spawners_id_last_used)
return 0; // full
Copy link
Member

Choose a reason for hiding this comment

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

is zero a valid id?
I suppose not, would be good to use std::optional<u32> for the return one day

Copy link
Member Author

Choose a reason for hiding this comment

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

I currently do not see any indicator that 0 is a reserved ID - neither on client- nor server-side. However, it will at least be more consistent other the ID assignments like in ActiveObjectMgr where 0 is reserved.

Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

LGTM

@SmallJoker SmallJoker merged commit a7e5456 into minetest:master Nov 29, 2023
13 checks passed
@Desour
Copy link
Member

Desour commented Nov 29, 2023

I didn't find time to test this before, sorry.

This introduced a bug: Sound ids are reused to early.
Reproduction:

  • Place 2 devtest jukeboxes.
  • With jukebox A, play a short sound, e.g. soundstuff_mono. Wait for it to end, do not release the handle.
  • With jukebox B, play a long or looped sound, e.g. some music.
  • Press stop sound in jukebox A.
  • Bug: This stops the sound of jukebox B.

@SmallJoker

To fix, either revert, or init free_id with m_playing_sounds_id_last_used+1.

cx384 pushed a commit to cx384/minetest that referenced this pull request Dec 9, 2023
…t#14045)

This improves the reliability when removing and re-adding handles quickly.
Looping through the entire ID range avoids collisions caused by any race condition.
kawogi pushed a commit to kawogi/minetest that referenced this pull request Dec 19, 2023
…t#14045)

This improves the reliability when removing and re-adding handles quickly.
Looping through the entire ID range avoids collisions caused by any race condition.
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.

ParticleSpawner (and maybe sound) IDs Reused
3 participants