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

Exit from a deadlock while playing Blood Lust sound on macOS #8698

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/fheroes2/battle/battle_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5372,7 +5372,7 @@ void Battle::Interface::RedrawActionBloodLustSpell( const Unit & target )

const uint32_t bloodlustDelay = 1800 / 20;
// duration is 1900ms
AudioManager::PlaySound( M82::BLOODLUS );
const int channelId = AudioManager::PlaySound( M82::BLOODLUS );

uint32_t alpha = 0;
uint32_t frame = 0;
Expand All @@ -5382,6 +5382,10 @@ void Battle::Interface::RedrawActionBloodLustSpell( const Unit & target )
// Make sure that the first run is passed immediately.
assert( !Game::isCustomDelayNeeded( bloodlustDelay ) );

// As reported by some players on macOS they are facing deadlock while making this spell.
// The deadlock comes from SDL_mixer which reports the sound being played.
fheroes2::Time timer;

while ( le.HandleEvents( Game::isCustomDelayNeeded( bloodlustDelay ) ) && Mixer::isPlaying( -1 ) ) {
CheckGlobalEvents( le );

Expand All @@ -5393,6 +5397,13 @@ void Battle::Interface::RedrawActionBloodLustSpell( const Unit & target )
alpha += ( frame < 10 ) ? 20 : -20;
++frame;
}

if ( frame >= 20 && timer.getS() > 20 ) {
// This is an extreme case of any sound being played.
// 20 seconds are good enough to make sure that any reasonable sound finishes playing.
ERROR_LOG( "Blood lust sound hasn't been detected as completed after 20 seconds for channel " << channelId )
break;
}
}

_currentUnit = nullptr;
Expand Down
Loading