fix(memory): Fix memory leak for audio events when pausing the game#2731
fix(memory): Fix memory leak for audio events when pausing the game#2731Caball009 wants to merge 1 commit into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/Common/Audio/AudioRequest.cpp | Adds destructor body that deletes m_pendingEvent when m_usePendingEvent is true — the core fix for the leak. |
| Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp | playAudioEvent now returns Bool tracking ownership; processRequest nulls m_pendingEvent on TRUE return to prevent double-free. |
| Core/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h | Declaration updated from void to Bool for playAudioEvent — minimal, correct change. |
Reviews (1): Last reviewed commit: "fix(memory): Fix memory leak for audio e..." | Re-trigger Greptile
| { | ||
| // TheSuperHackers @info The audio event is no longer owned by this request, because it was just processed. | ||
| // Reset pointer to prevent the destructor of the request from calling delete on the audio event. | ||
| req->m_pendingEvent = nullptr; |
There was a problem hiding this comment.
I could add req->m_usePendingEvent = FALSE here if desired. I don't think it makes a functional difference.
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