Skip to content

Commit

Permalink
Fix #5204
Browse files Browse the repository at this point in the history
When music was resumed, its status was switched to 'playing' without regard to the music play initialization steps having been done or not.
  • Loading branch information
Alayan-stk-2 committed Dec 24, 2024
1 parent 2c30427 commit 2fac72b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/audio/music_ogg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ MusicOggStream::MusicOggStream(float loop_start, float loop_end)
m_soundSource = -1;
m_pausedMusic = true;
m_playing.store(false);
m_play_initialized.store(false);
m_loop_start = loop_start;
m_loop_end = loop_end;
} // MusicOggStream
Expand Down Expand Up @@ -166,6 +167,7 @@ bool MusicOggStream::release()

m_soundSource = -1;
m_playing.store(false);
m_play_initialized.store(false);

return true;
} // release
Expand All @@ -187,6 +189,7 @@ bool MusicOggStream::playMusic()
alSourcePlay(m_soundSource);
m_pausedMusic = false;
m_playing.store(true);
m_play_initialized.store(true);
check("playMusic");
return true;
} // playMusic
Expand All @@ -195,15 +198,6 @@ bool MusicOggStream::playMusic()
bool MusicOggStream::isPlaying()
{
return m_playing.load();

/*
if (m_soundSource == -1) return false;
ALenum state;
alGetSourcei(m_soundSource, AL_SOURCE_STATE, &state);
return (state == AL_PLAYING);
*/
} // isPlaying

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -237,7 +231,8 @@ bool MusicOggStream::resumeMusic()
return true;
}

m_playing.store(true);
if(m_play_initialized.load()) // Avoid #5204
m_playing.store(true);

alSourcePlay(m_soundSource);
m_pausedMusic= false;
Expand Down
1 change: 1 addition & 0 deletions src/audio/music_ogg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class MusicOggStream : public Music
bool m_error;

std::atomic_bool m_playing;
std::atomic_bool m_play_initialized;

ALuint m_soundBuffers[2];
ALuint m_soundSource;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/sfx_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void SFXManager::mainLoop(void *obj)
current->m_music_information->pauseMusic(); break;
case SFX_MUSIC_RESUME:
current->m_music_information->resumeMusic();
// This might be necessasary if the volume was changed
// This might be necessary if the volume was changed
// in the in-game menu
current->m_music_information->setDefaultVolume(); break;
case SFX_MUSIC_SWITCH_FAST:
Expand Down

0 comments on commit 2fac72b

Please sign in to comment.