From c601d6a7e2079421627a77c5fcbd93716870e3c7 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 17 Sep 2022 16:13:15 -0400 Subject: audio: Do not crash if there are no audio devices available. --- chickadee/audio.scm | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/chickadee/audio.scm b/chickadee/audio.scm index 7b5b0f3..e7bce70 100644 --- a/chickadee/audio.scm +++ b/chickadee/audio.scm @@ -161,14 +161,19 @@ (guardian sound-system-guardian)) (define (make-sound-system) - (%make-sound-system (openal:make-context (openal:open-device)) - (make-array-list) - (make-hash-table) - (make-weak-key-hash-table) - (make-hash-table) - (make-array-list) - (make-hash-table) - (make-guardian))) + ;; It's possible that there are *no* audio devices available, in + ;; which case open-device throws an exception. In that case, return + ;; #f. + (let ((device (false-if-exception (openal:open-device)))) + (and device + (%make-sound-system (openal:make-context device) + (make-array-list) + (make-hash-table) + (make-weak-key-hash-table) + (make-hash-table) + (make-array-list) + (make-hash-table) + (make-guardian))))) (define (register-source sound-system source) (hashq-set! (sound-system-sources sound-system) source source) -- cgit v1.2.3