fix(memory): Fix audio event related memory leaks when pausing the game#2731
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/Common/Audio/AudioRequest.cpp | Adds destructor that deletes m_pendingEvent when owned, and releasePendingEvent() for safe ownership transfer — both correctly conditioned on m_usePendingEvent. |
| Core/GameEngine/Include/Common/AudioRequest.h | Declares releasePendingEvent() in the AudioRequest struct; no structural issues. |
| Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp | playAudioEvent signature changed to take AudioRequest*; releasePendingEvent() called at exactly one site per execution path (stream, 3D, 2D), leaving the destructor responsible for all early-exit cleanup. |
| Core/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h | Updates playAudioEvent declaration to match new AudioRequest* parameter — straightforward signature update. |
Sequence Diagram
sequenceDiagram
participant PRL as processRequestList
participant AR as AudioRequest
participant PAE as playAudioEvent
participant PA as PlayingAudio
PRL->>AR: deleteInstance(req) [pause path]
Note over AR: destructor sees m_usePendingEvent==true, deletes m_pendingEvent
PRL->>PAE: playAudioEvent(req) [normal path]
PAE->>PAE: "event = req->m_pendingEvent (read only)"
alt early return due to missing info
PAE-->>PRL: return
Note over AR: destructor deletes m_pendingEvent since m_usePendingEvent still true
else stream or 3D or 2D sample branch
PAE->>AR: releasePendingEvent()
Note over AR: sets m_usePendingEvent=false and m_pendingEvent=nullptr
AR-->>PAE: "AudioEventRTS* (ownership transferred)"
PAE->>PA: "audio->m_audioEventRTS = event"
Note over PA: releasePlayingAudio frees it later
end
PRL->>AR: deleteInstance(req)
Note over AR: destructor sees m_usePendingEvent==false, no double-delete
Reviews (6): Last reviewed commit: "Reverted some of the changes to use 'eve..." | Re-trigger Greptile
057637e to
977bd8b
Compare
977bd8b to
afb337c
Compare
|
Rebased to include the fix for the CI Replay checker. |
9e09418 to
08f2330
Compare
08f2330 to
130a39f
Compare
…nAL playAudioEvent (fix double-free after upstream TheSuperHackers#2731)
…nAL playAudioEvent (fix double-free after upstream TheSuperHackers#2731)
Pausing the game leaks audio events that were in the audio request container at the time. This PR fixes that.
This code is called to get rid of some of the audio requests when pausing the game:
GeneralsGameCode/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
Lines 587 to 601 in 2219f63
AudioRequest::m_pendingEventcan be an owning raw pointer, though, which the destructor ofAudioRequestshould delete when needed. It currently doesn't, which is why the leak happens.GeneralsGameCode/Core/GameEngine/Include/Common/AudioRequest.h
Line 51 in 2219f63
There's one exception where the ownership of the audio event is taken away from the audio request:
GeneralsGameCode/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
Line 2238 in 2219f63