From 3174141b23c7513f32a9a5e31214e4b506636f4d Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 18 Jan 2008 15:10:25 +0000 Subject: [PATCH] Fixed AudioContext.IsCurrent getter (would throw if no context was current). --- Source/Examples/OpenAL/TestAudioContext.cs | 35 +++++++++++++++++----- Source/OpenTK/OpenAL/AudioContext.cs | 4 ++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Source/Examples/OpenAL/TestAudioContext.cs b/Source/Examples/OpenAL/TestAudioContext.cs index 63ce0dfd..0131c25a 100644 --- a/Source/Examples/OpenAL/TestAudioContext.cs +++ b/Source/Examples/OpenAL/TestAudioContext.cs @@ -6,18 +6,20 @@ using OpenTK.Audio; using AlContext = System.IntPtr; using AlDevice = System.IntPtr; +using System.Diagnostics; namespace Examples { [Example("AudioContext Test", ExampleCategory.Test)] class TestApp { - public static void GetOpenALErrors( IntPtr device ) + public static void PrintOpenALErrors( IntPtr device ) { - ALError AlErr = AL.GetError( ); - AlcError AlcErr = Alc.GetError( device ); - AlutError AlutErr = Alut.GetError( ); - Console.WriteLine( " Al: " + AlErr + " Alc: " + AlcErr + " Alut: " + AlcErr + " " + Alut.GetErrorString( AlutErr ) ); + ALError AlErr = AL.GetError(); + // AudioContext should throw on errors, so no need to test them manually. + //AlcError AlcErr = Alc.GetError(device); + AlutError AlutErr = Alut.GetError(); + Console.WriteLine("Al: " + AlErr + " Alut: " + Alut.GetErrorString(AlutErr)); } public static void Main() @@ -29,7 +31,26 @@ namespace Examples { AudioContext context = new AudioContext(); - /* + Trace.WriteLine("Testing AudioContext functions."); + Trace.Indent(); + + Trace.WriteLine("Suspend()..."); + context.Suspend(); + Trace.Assert(!context.IsProcessing); + + Trace.WriteLine("Process()..."); + context.Process(); + Trace.Assert(context.IsProcessing); + + Trace.WriteLine("MakeCurrent()..."); + context.MakeCurrent(); + Trace.Assert(context.IsCurrent); + + Trace.WriteLine("IsCurrent = false..."); + context.IsCurrent = false; + Trace.Assert(!context.IsCurrent); + +#if false AlDevice MyDevice; AlContext MyContext; @@ -100,7 +121,7 @@ namespace Examples { Console.WriteLine( "Failed to find suitable Device." ); } - */ +#endif /* include include diff --git a/Source/OpenTK/OpenAL/AudioContext.cs b/Source/OpenTK/OpenAL/AudioContext.cs index 80fde68b..5fe5d0ee 100644 --- a/Source/OpenTK/OpenAL/AudioContext.cs +++ b/Source/OpenTK/OpenAL/AudioContext.cs @@ -348,7 +348,9 @@ namespace OpenTK.Audio if (available_contexts.Count == 0) return false; else - return AudioContext.available_contexts[(ContextHandle)Alc.GetCurrentContext()] == this; + { + return AudioContext.CurrentContext == this; + } } } set