From 0890bd8d3f53bb1813ef3e4a82d73c8243694626 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sun, 26 Mar 2023 20:29:38 +0800 Subject: [PATCH] safety checks --- .../src/AudioSystem/SHAudioSystem.cpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp index 749f6180..c67903da 100644 --- a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp +++ b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp @@ -422,7 +422,12 @@ namespace SHADE if(auto it = eventMap.find(path); it != eventMap.end()) { audioClipHandle = audioClipLibrary.Create(); - it->second->createInstance(&audioClipHandle->instance); + result = it->second->createInstance(&audioClipHandle->instance); + if(result != FMOD_OK) + { + SHLOG_ERROR("Failed to create AudioClip with path {}", path) + ErrorCheck(); + } } else { @@ -681,6 +686,7 @@ namespace SHADE result = fmodStudioSystem->getParameterByName(path, &value); if(result != FMOD_OK) { + SHLOG_ERROR("AudioSys_GetParam"); ErrorCheck(); } return value; @@ -691,6 +697,7 @@ namespace SHADE result = fmodStudioSystem->setParameterByName(path, value); if (result != FMOD_OK) { + SHLOG_ERROR("AudioSys_SetParam"); ErrorCheck(); } } @@ -700,6 +707,7 @@ namespace SHADE result = fmodStudioSystem->setParameterByNameWithLabel(path, label); if (result != FMOD_OK) { + SHLOG_ERROR("AudioSys_SetParamWithLabel"); ErrorCheck(); } } @@ -708,9 +716,12 @@ namespace SHADE { if(!instance) return; + if(!instance->isValid()) + return; FMOD_RESULT result = instance->start(); if (result != FMOD_OK) { + SHLOG_ERROR("AudioClip_Play"); SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) } } @@ -746,9 +757,12 @@ namespace SHADE { if (!instance) return; + if(!instance->isValid()) + return; FMOD_RESULT result = instance->stop(fadeOut ? FMOD_STUDIO_STOP_ALLOWFADEOUT : FMOD_STUDIO_STOP_IMMEDIATE); if (result != FMOD_OK) { + SHLOG_ERROR("AudioClip_Stop"); SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) } } @@ -778,7 +792,7 @@ namespace SHADE FMOD_RESULT result = instance->setParameterByName(paramName, value); if (result != FMOD_OK) { - SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) + SHLOG_ERROR("AudioClip::Play error: {}", FMOD_ErrorString(result)) } } @@ -789,7 +803,7 @@ namespace SHADE FMOD_RESULT result = instance->setParameterByNameWithLabel(paramName, label); if (result != FMOD_OK) { - SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) + SHLOG_ERROR("AudioClip::SetParamWithLabel error: {}", FMOD_ErrorString(result)) } } @@ -801,7 +815,7 @@ namespace SHADE auto result = instance->getParameterByName(paramName, &value); if (result != FMOD_OK) { - SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) + SHLOG_ERROR("AudioClip::GetParam error: {}", FMOD_ErrorString(result)) } return value; }