From 2842df5a02b5a65b9977a64de8ea6bea8adbc964 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 9 Oct 2019 00:11:19 -0700 Subject: [PATCH] Catch exceptions from backend start calls --- alc/alc.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/alc/alc.cpp b/alc/alc.cpp index 025395fe..7702a147 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2241,9 +2241,16 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(!device->Flags.get()) { - if(device->Backend->start() == false) + try { + auto backend = device->Backend.get(); + if(!backend->start()) + throw al::backend_exception{ALC_INVALID_DEVICE, "Backend error"}; + device->Flags.set(); + } + catch(al::backend_exception& e) { + WARN("Failed to start playback: %s\n", e.what()); return ALC_INVALID_DEVICE; - device->Flags.set(); + } } return ALC_NO_ERROR; @@ -3874,11 +3881,14 @@ START_API_FUNC alcSetError(dev.get(), ALC_INVALID_DEVICE); else if(!dev->Flags.get()) { - if(dev->Backend->start()) + try { + auto backend = dev->Backend.get(); + if(!backend->start()) + throw al::backend_exception{ALC_INVALID_DEVICE, "Device start failure"}; dev->Flags.set(); - else - { - aluHandleDisconnect(dev.get(), "Device start failure"); + } + catch(al::backend_exception& e) { + aluHandleDisconnect(dev.get(), "%s", e.what()); alcSetError(dev.get(), ALC_INVALID_DEVICE); } } @@ -4101,13 +4111,16 @@ START_API_FUNC if(dev->mContexts.load()->empty()) return; - if(dev->Backend->start() == false) - { - aluHandleDisconnect(dev.get(), "Device start failure"); - alcSetError(dev.get(), ALC_INVALID_DEVICE); - return; + try { + auto backend = dev->Backend.get(); + if(!backend->start()) + throw al::backend_exception{ALC_INVALID_DEVICE, "Device start failure"}; + dev->Flags.set(); + } + catch(al::backend_exception& e) { + aluHandleDisconnect(dev.get(), "%s", e.what()); + alcSetError(dev.get(), ALC_INVALID_DEVICE); } - dev->Flags.set(); } END_API_FUNC