Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Source/Managers/AudioMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ bool AudioMan::Initialize() {
void AudioMan::Destroy() {
if (m_AudioEnabled) {
StopAll();
// FMOD loads sounds on a thread of its own, which crashes if the audio system gets released while it's still at it. That's the case when quitting shortly after launching.
// Releasing a sound waits for it to be done loading, and FMOD wants them all released before the audio system anyway.
ContentFile::FreeAllLoadedSounds();
m_AudioSystem->release();
Clear();
}
Expand Down
9 changes: 9 additions & 0 deletions Source/System/ContentFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ void ContentFile::FreeAllLoaded() {
}
}

void ContentFile::FreeAllLoadedSounds() {
for (const auto& [soundPath, sound]: s_LoadedSamples) {
if (sound) {
sound->release();
}
}
s_LoadedSamples.clear();
}

int ContentFile::ReadProperty(const std::string_view& propName, Reader& reader) {
StartPropertyList(return Serializable::ReadProperty(propName, reader));

Expand Down
3 changes: 3 additions & 0 deletions Source/System/ContentFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ namespace RTE {

/// Frees all loaded data used by all ContentFile instances. This should ONLY be done when quitting the app, or after everything else is completely destroyed.
static void FreeAllLoaded();

/// Releases all the sounds loaded by all ContentFile instances, waiting for the ones FMOD is still loading asynchronously. This has to be done before the audio system gets released.
static void FreeAllLoadedSounds();
#pragma endregion

#pragma region Getters and Setters
Expand Down
Loading