aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/alc.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-05-04 18:03:25 -0700
committerChris Robinson <[email protected]>2019-05-04 18:03:25 -0700
commit5ff8d5ae32943c5325172799f31b7c5b66c4f054 (patch)
tree1920073d9a1325f8d203fa187e2a9bf1b7d8b011 /Alc/alc.cpp
parent1607f9c525eedb4af5b736990fd4e6640f37def0 (diff)
Add an exception class to cover backend creation and opening
Diffstat (limited to 'Alc/alc.cpp')
-rw-r--r--Alc/alc.cpp76
1 files changed, 41 insertions, 35 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index 3bc365c8..9b4c2978 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -3680,20 +3680,22 @@ START_API_FUNC
device->AuxiliaryEffectSlotMax = 64;
device->NumAuxSends = DEFAULT_SENDS;
- /* Create the device backend. */
- device->Backend = PlaybackBackend.getFactory().createBackend(device.get(),
- BackendType::Playback);
- if(!device->Backend)
- {
- alcSetError(nullptr, ALC_OUT_OF_MEMORY);
- return nullptr;
+ try {
+ /* Create the device backend. */
+ device->Backend = PlaybackBackend.getFactory().createBackend(device.get(),
+ BackendType::Playback);
+
+ /* Find a playback device to open */
+ ALCenum err{device->Backend->open(deviceName)};
+ if(err != ALC_NO_ERROR)
+ {
+ alcSetError(nullptr, err);
+ return nullptr;
+ }
}
-
- /* Find a playback device to open */
- ALCenum err{device->Backend->open(deviceName)};
- if(err != ALC_NO_ERROR)
- {
- alcSetError(nullptr, err);
+ catch(al::backend_exception &e) {
+ WARN("Failed to open playback device: %s\n", e.what());
+ alcSetError(nullptr, e.errorCode());
return nullptr;
}
@@ -3934,21 +3936,23 @@ START_API_FUNC
device->UpdateSize = samples;
device->BufferSize = samples;
- device->Backend = CaptureBackend.getFactory().createBackend(device.get(),
- BackendType::Capture);
- if(!device->Backend)
- {
- alcSetError(nullptr, ALC_OUT_OF_MEMORY);
- return nullptr;
- }
+ try {
+ device->Backend = CaptureBackend.getFactory().createBackend(device.get(),
+ BackendType::Capture);
- TRACE("Capture format: %s, %s, %uhz, %u / %u buffer\n",
- DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
- device->Frequency, device->UpdateSize, device->BufferSize);
- ALCenum err{device->Backend->open(deviceName)};
- if(err != ALC_NO_ERROR)
- {
- alcSetError(nullptr, err);
+ TRACE("Capture format: %s, %s, %uhz, %u / %u buffer\n",
+ DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
+ device->Frequency, device->UpdateSize, device->BufferSize);
+ ALCenum err{device->Backend->open(deviceName)};
+ if(err != ALC_NO_ERROR)
+ {
+ alcSetError(nullptr, err);
+ return nullptr;
+ }
+ }
+ catch(al::backend_exception &e) {
+ WARN("Failed to open capture device: %s\n", e.what());
+ alcSetError(nullptr, e.errorCode());
return nullptr;
}
@@ -4108,17 +4112,19 @@ START_API_FUNC
device->NumStereoSources = 1;
device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
- device->Backend = LoopbackBackendFactory::getFactory().createBackend(device.get(),
- BackendType::Playback);
- if(!device->Backend)
- {
- alcSetError(nullptr, ALC_OUT_OF_MEMORY);
+ try {
+ device->Backend = LoopbackBackendFactory::getFactory().createBackend(device.get(),
+ BackendType::Playback);
+
+ // Open the "backend"
+ device->Backend->open("Loopback");
+ }
+ catch(al::backend_exception &e) {
+ WARN("Failed to open loopback device: %s\n", e.what());
+ alcSetError(nullptr, e.errorCode());
return nullptr;
}
- // Open the "backend"
- device->Backend->open("Loopback");
-
{
std::lock_guard<std::recursive_mutex> _{ListLock};
auto iter = std::lower_bound(DeviceList.cbegin(), DeviceList.cend(), device.get());