From 9851a3bab9a5689aaa96770a8603083f02ac6cc7 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Mon, 29 Sep 2014 23:37:40 +0200 Subject: [PATCH] [AL] Fix runtime crash when OpenAL not available Issue reported at http://www.opentk.com/node/3805 We must not throw exceptions from a finalizer, as this leads to the runtime forcibly taking down the application. --- Source/OpenTK/Audio/AudioDeviceEnumerator.cs | 22 ++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/OpenTK/Audio/AudioDeviceEnumerator.cs b/Source/OpenTK/Audio/AudioDeviceEnumerator.cs index 6b3f7419..a5ffea8f 100644 --- a/Source/OpenTK/Audio/AudioDeviceEnumerator.cs +++ b/Source/OpenTK/Audio/AudioDeviceEnumerator.cs @@ -204,12 +204,22 @@ namespace OpenTK.Audio { Debug.Unindent(); - // clean up the dummy context - Alc.MakeContextCurrent(ContextHandle.Zero); - if (dummy_context != ContextHandle.Zero && dummy_context.Handle != IntPtr.Zero) - Alc.DestroyContext(dummy_context); - if (dummy_device != IntPtr.Zero) - Alc.CloseDevice(dummy_device); + if (openal_supported) + { + try + { + // clean up the dummy context + Alc.MakeContextCurrent(ContextHandle.Zero); + if (dummy_context != ContextHandle.Zero && dummy_context.Handle != IntPtr.Zero) + Alc.DestroyContext(dummy_context); + if (dummy_device != IntPtr.Zero) + Alc.CloseDevice(dummy_device); + } + catch + { + openal_supported = false; + } + } } }