Do not call SDL.GetVersion unless requested

This commit is contained in:
Stefanos A. 2013-11-18 18:35:23 +01:00
parent 635bb85313
commit 32828ecd8a

View file

@ -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> 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)]