Fix XAudio2 and OpenAL errors on shutdown, improve cinematic audio queue mgmt

(cherry picked from commit 4bfdf622f94b52eae52faece058c0e3d6139551e)
This commit is contained in:
Stephen Saunders 2022-02-22 15:38:56 -05:00
parent 22cd420513
commit f24d7ecc16
3 changed files with 29 additions and 32 deletions

View file

@ -1571,10 +1571,6 @@ void idCommonLocal::Shutdown()
printf( "uiManager->Shutdown();\n" );
uiManager->Shutdown();
// shut down the sound system
printf( "soundSystem->Shutdown();\n" );
soundSystem->Shutdown();
// shut down the user command input code
printf( "usercmdGen->Shutdown();\n" );
usercmdGen->Shutdown();
@ -1584,9 +1580,16 @@ void idCommonLocal::Shutdown()
eventLoop->Shutdown();
// shutdown the decl manager
// SRS - Note this also shuts down all cinematic resources, including cinematic audio voices
printf( "declManager->Shutdown();\n" );
declManager->Shutdown();
// shut down the sound system
// SRS - Shut down sound system after decl manager so cinematic audio voices are destroyed first
// Important for XAudio2 where the mastering voice cannot be destroyed if any other voices exist
printf( "soundSystem->Shutdown();\n" );
soundSystem->Shutdown();
// shut down the renderSystem
printf( "renderSystem->Shutdown();\n" );
renderSystem->Shutdown();

View file

@ -205,30 +205,25 @@ void CinematicAudio_OpenAL::ResetAudio()
alSourcei( alMusicSourceVoicecin, AL_BUFFER, 0 );
}
if( !tBuffer.empty() )
while( !tBuffer.empty() )
{
int buffersize = tBuffer.size();
while( buffersize > 0 )
uint8_t* tempdata = tBuffer.front();
tBuffer.pop();
sizes.pop();
if( tempdata )
{
uint8_t* tempdata = tBuffer.front();
tBuffer.pop();
// SRS - We must free any audio buffers that have not been copied into an alBuffer
#if defined(USE_FFMPEG)
av_freep( &tempdata );
#elif defined(USE_BINKDEC)
Mem_Free( tempdata );
#endif
buffersize--;
}
}
if( !sizes.empty() )
while( !bufids.empty() )
{
int buffersize = sizes.size();
while( buffersize > 0 )
{
sizes.pop();
buffersize--;
}
bufids.pop();
}
offset = 0;
@ -252,29 +247,25 @@ void CinematicAudio_OpenAL::ShutdownAudio()
{
alDeleteBuffers( NUM_BUFFERS, alMusicBuffercin );
}
if( !tBuffer.empty() )
while( !tBuffer.empty() )
{
int buffersize = tBuffer.size();
while( buffersize > 0 )
uint8_t* tempdata = tBuffer.front();
tBuffer.pop();
sizes.pop();
if( tempdata )
{
uint8_t* tempdata = tBuffer.front();
tBuffer.pop();
// SRS - We must free any audio buffers that have not been copied into an alBuffer
#if defined(USE_FFMPEG)
av_freep( &tempdata );
#elif defined(USE_BINKDEC)
Mem_Free( tempdata );
#endif
buffersize--;
}
}
if( !sizes.empty() )
while( !bufids.empty() )
{
int buffersize = sizes.size();
while( buffersize > 0 )
{
sizes.pop();
buffersize--;
}
bufids.pop();
}
}

View file

@ -206,11 +206,14 @@ void idSoundVoice_OpenAL::DestroyInternal()
idLib::Printf( "%dms: %i destroyed\n", Sys_Milliseconds(), openalSource );
}
// SRS - Make sure the source is stopped before detaching buffers
alSourceStop( openalSource );
alSourcei( openalSource, AL_BUFFER, 0 );
// SRS - Delete source only after detaching buffers above
alDeleteSources( 1, &openalSource );
openalSource = 0;
alSourcei( openalSource, AL_BUFFER, 0 );
if( openalStreamingBuffer[0] && openalStreamingBuffer[1] && openalStreamingBuffer[2] )
{
CheckALErrors();