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

Fix sound and particlespawner id generation #14059

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2172,15 +2172,16 @@ void Server::SendPlayerSpeed(session_t peer_id, const v3f &added_vel)
inline s32 Server::nextSoundId()
{
s32 free_id = m_playing_sounds_id_last_used;
while (free_id == 0 || m_playing_sounds.find(free_id) != m_playing_sounds.end()) {
do {
if (free_id == INT32_MAX)
free_id = 0; // signed overflow is undefined
else
free_id++;

if (free_id == m_playing_sounds_id_last_used)
return 0;
}
} while (free_id == 0 || m_playing_sounds.find(free_id) != m_playing_sounds.end());

m_playing_sounds_id_last_used = free_id;
return free_id;
}
Expand Down
6 changes: 3 additions & 3 deletions src/serverenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,11 @@ u32 ServerEnvironment::addParticleSpawner(float exptime)
float time = exptime > 0.f ? exptime : PARTICLE_SPAWNER_NO_EXPIRY;

u32 free_id = m_particle_spawners_id_last_used;
while (free_id == 0 || m_particle_spawners.find(free_id) != m_particle_spawners.end()) {
do {
free_id++;
if (free_id == m_particle_spawners_id_last_used)
return 0; // full
free_id++;
}
} while (free_id == 0 || m_particle_spawners.find(free_id) != m_particle_spawners.end());

m_particle_spawners_id_last_used = free_id;
m_particle_spawners[free_id] = time;
Expand Down