From 32828ecd8afb1ff76f58f7a724e816077539808c Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Mon, 18 Nov 2013 18:35:23 +0100 Subject: [PATCH] Do not call SDL.GetVersion unless requested --- Source/OpenTK/Platform/SDL2/Sdl2.cs | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Source/OpenTK/Platform/SDL2/Sdl2.cs b/Source/OpenTK/Platform/SDL2/Sdl2.cs index 352e085d..2ec6c2a7 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2.cs @@ -29,6 +29,7 @@ using System.Runtime.InteropServices; #endregion using System; +using System.Diagnostics; using System.Security; using System.Runtime.InteropServices; @@ -46,17 +47,25 @@ namespace OpenTK.Platform.SDL2 #endif public readonly static object Sync = new object(); - public readonly static Version Version; - - static SDL() + static Nullable version; + public static Version Version { - try + get { - GetVersion(out Version); - } - catch - { - // nom nom + try + { + if (!version.HasValue) + { + version = GetVersion(); + } + return version.Value; + } + catch + { + // nom nom + Debug.Print("[SDL2] Failed to retrieve version"); + return new Version(); + } } } @@ -140,6 +149,12 @@ namespace OpenTK.Platform.SDL2 [SuppressUnmanagedCodeSecurity] [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetVersion", ExactSpelling = true)] public static extern void GetVersion(out Version version); + public static Version GetVersion() + { + Version v; + GetVersion(out v); + return v; + } [SuppressUnmanagedCodeSecurity] [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetWindowID", ExactSpelling = true)]