From baf59abb6ecbf47b4fec89f247fb555ec5204b36 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Tue, 22 Jan 2008 21:18:47 +0000 Subject: [PATCH] Disabled multiple AudioContext under linux. Moved AudioContext.LoadAvailableDevices() call outside the static constructor. --- Source/Examples/OpenAL/TestAudioContext.cs | 12 ++++++------ Source/OpenTK/OpenAL/AudioContext.cs | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Source/Examples/OpenAL/TestAudioContext.cs b/Source/Examples/OpenAL/TestAudioContext.cs index ffadc8c7..cf3ba4f9 100644 --- a/Source/Examples/OpenAL/TestAudioContext.cs +++ b/Source/Examples/OpenAL/TestAudioContext.cs @@ -52,13 +52,13 @@ namespace Examples context.MakeCurrent(); Trace.Assert(context.IsCurrent); - Trace.WriteLine("IsCurrent = false..."); - context.IsCurrent = false; - Trace.Assert(!context.IsCurrent); + //Trace.WriteLine("IsCurrent = false..."); + //context.IsCurrent = false; + //Trace.Assert(!context.IsCurrent); - Trace.WriteLine("IsCurrent = true..."); - context.IsCurrent = true; - Trace.Assert(context.IsCurrent); + //Trace.WriteLine("IsCurrent = true..."); + //context.IsCurrent = true; + //Trace.Assert(context.IsCurrent); Trace.WriteLine("AudioContext.CurrentContext..."); Trace.Assert(AudioContext.CurrentContext == context); diff --git a/Source/OpenTK/OpenAL/AudioContext.cs b/Source/OpenTK/OpenAL/AudioContext.cs index c3bfc93d..8448eb89 100644 --- a/Source/OpenTK/OpenAL/AudioContext.cs +++ b/Source/OpenTK/OpenAL/AudioContext.cs @@ -41,10 +41,10 @@ namespace OpenTK.Audio /// /// Runs before the actual class constructor, to load available devices. /// - static AudioContext() - { - LoadAvailableDevices(); - } + //static AudioContext() + //{ + // LoadAvailableDevices(); + //} #endregion @@ -208,6 +208,13 @@ namespace OpenTK.Audio if (maxEfxSends < 0) throw new ArgumentOutOfRangeException("maxEfxSends", maxEfxSends, "Should be greater than zero."); //if (available_devices.Count == 0) throw new NotSupportedException("No audio hardware is available."); + if (available_devices.Count == 0) + LoadAvailableDevices(); + + // HACK: Do not allow multiple contexts under linux (crashes under Ubuntu 7.04 and 7.10) + if (available_contexts.Count > 0) + throw new NotSupportedException("Multiple AudioContexts are not supported under Linux."); + device_handle = Alc.OpenDevice(device); if (device_handle == IntPtr.Zero) throw new AudioDeviceException("The specified audio device does not exist or is tied up by another application."); @@ -215,7 +222,7 @@ namespace OpenTK.Audio CheckForAlcErrors(); device_name = device; - /* + // Build the attribute list List attributes = new List(); @@ -243,8 +250,7 @@ namespace OpenTK.Audio } context_handle = Alc.CreateContext(device_handle, attributes.ToArray()); - */ - context_handle = Alc.CreateContext(device_handle, (int[])null); + if (context_handle == IntPtr.Zero) { Alc.CloseDevice(device_handle); @@ -318,6 +324,8 @@ namespace OpenTK.Audio { get { + if (available_devices.Count == 0) + LoadAvailableDevices(); return available_devices.ToArray(); } }