Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(audio): an audio request began life holding whatever was in the block
Olcay Seygan8ad00299bc39
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h b/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.hindex 2fd52984b..734a6d3b0 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h@@ -49,14 +49,32 @@ struct AudioRequest : public MemoryPoolObjectpublic:RequestType m_request;- union- {- AudioEventRTS *m_pendingEvent;- AudioHandle m_handleToInteractOn;- };++ //+ // These two used to share a union, told apart by m_usePendingEvent. A play request fills in+ // the event pointer, so the kill-by-handle search compared a pointer against a handle, never+ // matched, and a sound killed before it started played anyway. They are eight bytes; sharing+ // them bought nothing and cost that.+ //+ AudioEventRTS *m_pendingEvent;+ AudioHandle m_handleToInteractOn;+Bool m_usePendingEvent;Bool m_requiresCheckForSample;+ //+ // The pool hands out raw memory, and allocateAudioRequest only ever set m_usePendingEvent.+ // Between that call and the caller assigning the event, m_pendingEvent held whatever the last+ // occupant of the block left there - which the destructor would then delete.+ //+ AudioRequest()+ : m_request(AR_Play),+ m_pendingEvent(NULL),+ m_handleToInteractOn(0),+ m_usePendingEvent(FALSE),+ m_requiresCheckForSample(FALSE)+ { }+/** A play request owns the event it is carrying until something takes it - the destructor frees* whatever is left, so a request dropped without being processed no longer leaks it. */AudioEventRTS *releasePendingEvent();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cppindex b4d16d016..6da009510 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp@@ -1009,9 +1009,8 @@ void MilesAudioManager::killAudioEventImmediately( AudioHandle audioEvent )for( ait = m_audioRequests.begin(); ait != m_audioRequests.end(); ait++ ){AudioRequest *req = (*ait);- // m_handleToInteractOn and m_pendingEvent share one union, and a play request fills in the- // event pointer - so this compared a pointer against a handle, never matched, and a sound- // killed before it started played anyway.+ // A play request carries the event, not the handle, so the match is on the event's handle.+ // The two used to share a union and this compared a pointer against a handle instead.if( req && req->m_usePendingEvent && req->m_pendingEvent&& req->m_pendingEvent->getPlayingHandle() == audioEvent ){