From bd9af625129b75c3ba67c38d5871fd00b847e5f1 Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Wed, 17 Jun 2026 15:52:57 +0200 Subject: [PATCH] AmbisonicBinauralizer: Handle exceptions initializing HRTF As a follow up to 5dda58ee0bee3ec808d01b044dcf7392b7d30c3d, handle exceptions when initializing the HRTF object. Not only will this catch the newly raised exception when mysofa fails to initialize, but it will also handle allocation failure exceptions more gracefully here by just returning a nullptr. Ref #88 --- include/SpatialaudioVersion.h | 2 +- source/AmbisonicBinauralizer.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/SpatialaudioVersion.h b/include/SpatialaudioVersion.h index 9948f5a..22931b7 100644 --- a/include/SpatialaudioVersion.h +++ b/include/SpatialaudioVersion.h @@ -30,7 +30,7 @@ /** * libspatialaudio patch API version */ -#define SPATIALAUDIO_API_VERSION_PATCH 0 +#define SPATIALAUDIO_API_VERSION_PATCH 1 #define SPATIALAUDIO_API_VERSION_STRING \ SPAUDIO_CONCACT_VERSION(SPATIALAUDIO_API_VERSION_MAJOR, \ diff --git a/source/AmbisonicBinauralizer.cpp b/source/AmbisonicBinauralizer.cpp index a260d0a..edbe5a6 100644 --- a/source/AmbisonicBinauralizer.cpp +++ b/source/AmbisonicBinauralizer.cpp @@ -387,24 +387,25 @@ namespace spaudio { { HRTF* p_hrtf; + try { #if SPATIALAUDIO_SUPPORTS_SOFA # if SPATIALAUDIO_SUPPORTS_MIT_HRTF - if (HRTFPath == "") - p_hrtf = new MIT_HRTF(nSampleRate); - else + if (HRTFPath == "") + p_hrtf = new MIT_HRTF(nSampleRate); + else # endif - p_hrtf = new SOFA_HRTF(HRTFPath, nSampleRate); + p_hrtf = new SOFA_HRTF(HRTFPath, nSampleRate); #else # if SPATIALAUDIO_SUPPORTS_MIT_HRTF - p_hrtf = new MIT_HRTF(nSampleRate); - (void)HRTFPath; + p_hrtf = new MIT_HRTF(nSampleRate); + (void)HRTFPath; # else # error At least MySOFA or MIT_HRTF need to be enabled # endif #endif - - if (p_hrtf == nullptr) + } catch (...) { return nullptr; + } if (!p_hrtf->isLoaded()) {