Skip to content

Commit 510c61a

Browse files
authored
Merge pull request #172 from cortex-command-community/musicman-use-after-free
Null NextSongSection properly - fix Mac/Linux crash when playing DynamicSongs
2 parents 8993e9d + 8cdb2cc commit 510c61a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Source/Entities/DynamicSong.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ SoundContainer& DynamicSongSection::SelectTransitionSoundContainer() {
167167
}
168168

169169
SoundContainer& DynamicSongSection::SelectSoundContainer() {
170+
RTEAssert(!m_SoundContainers.empty(), "Tried to get a SoundContainer from a DynamicSongSection with none to choose from!");
171+
170172
// Shuffle between our options if we have multiple
171173
if (m_SoundContainers.size() > 1) {
172174
if (m_ShuffleUnplayedIndices.empty()) {
@@ -199,8 +201,7 @@ SoundContainer& DynamicSongSection::SelectSoundContainer() {
199201
}
200202
}
201203
}
202-
203-
RTEAssert(!m_SoundContainers.empty(), "Tried to get a SoundContainer from a DynamicSongSection with none to choose from!");
204+
204205
return m_SoundContainers[0];
205206
}
206207

Source/Managers/MusicMan.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void MusicMan::ResetMusicState() {
100100

101101
bool MusicMan::PlayDynamicSong(const std::string& songName, const std::string& songSectionType, bool playImmediately, bool playTransition, bool smoothFade) {
102102
if (const DynamicSong* dynamicSongToPlay = dynamic_cast<const DynamicSong*>(g_PresetMan.GetEntityPreset("DynamicSong", songName))) {
103+
m_NextSongSection = nullptr;
103104
m_CurrentSong = std::unique_ptr<DynamicSong>(dynamic_cast<DynamicSong*>(dynamicSongToPlay->Clone()));
104105
SetNextSongSectionType(songSectionType);
105106
SelectNextSongSection();

0 commit comments

Comments
 (0)