Permalink
Browse files

Do not call SDL.GetVersion unless requested

  • Loading branch information...
thefiddler committed Nov 18, 2013
1 parent 635bb85 commit 32828ecd8afb1ff76f58f7a724e816077539808c
Showing with 24 additions and 9 deletions.
  1. +24 −9 Source/OpenTK/Platform/SDL2/Sdl2.cs
@@ -29,6 +29,7 @@
#endregion
using System;
+using System.Diagnostics;
using System.Security;
using System.Runtime.InteropServices;
@@ -46,17 +47,25 @@ partial class SDL
#endif
public readonly static object Sync = new object();
- public readonly static Version Version;
-
- static SDL()
+ static Nullable<Version> version;
+ public static Version Version
{
- try
- {
- GetVersion(out Version);
- }
- catch
+ get
{
- // 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 @@ public static string GetError()
[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)]

0 comments on commit 32828ec

Please sign in to comment.