Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #4

Sdl2InputDriver.Dispose() would call SDL_DelEventWatch with a different
"user_data" parameter than SDL_AdEventWatch. This caused the EventFilter
to remain registered and subsequently crash when closing and reopening a
window.
  • Loading branch information...
commit 48803bb4d620009ea3b9aab6981f6800a2b3793e 1 parent 255f4e9
@thefiddler thefiddler authored
View
8 Source/OpenTK/Platform/SDL2/Sdl2.cs
@@ -84,6 +84,10 @@ static string IntPtrToString(IntPtr ptr)
public static extern void AddEventWatch(EventFilter filter, IntPtr userdata);
[SuppressUnmanagedCodeSecurity]
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_AddEventWatch", ExactSpelling = true)]
+ public static extern void AddEventWatch(IntPtr filter, IntPtr userdata);
+
+ [SuppressUnmanagedCodeSecurity]
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_CreateRGBSurfaceFrom", ExactSpelling = true)]
public static extern IntPtr CreateRGBSurfaceFrom(IntPtr pixels,
int width, int height, int depth, int pitch,
@@ -103,6 +107,10 @@ static string IntPtrToString(IntPtr ptr)
public static extern void DelEventWatch(EventFilter filter, IntPtr userdata);
[SuppressUnmanagedCodeSecurity]
+ [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_DelEventWatch", ExactSpelling = true)]
+ public static extern void DelEventWatch(IntPtr filter, IntPtr userdata);
+
+ [SuppressUnmanagedCodeSecurity]
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_DestroyWindow", ExactSpelling = true)]
public static extern void DestroyWindow(IntPtr window);
View
6 Source/OpenTK/Platform/SDL2/Sdl2InputDriver.cs
@@ -45,7 +45,8 @@ class Sdl2InputDriver : IInputDriver2, IInputDriver
readonly Sdl2Mouse mouse_driver = new Sdl2Mouse();
readonly Sdl2JoystickDriver joystick_driver = new Sdl2JoystickDriver();
- readonly EventFilter EventFilterDelegate = FilterInputEvents;
+ readonly EventFilter EventFilterDelegate_GCUnsafe = FilterInputEvents;
+ readonly IntPtr EventFilterDelegate;
static int count;
bool disposed;
@@ -54,6 +55,7 @@ public Sdl2InputDriver()
{
lock (SDL.Sync)
{
+ EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
driver_handle = new IntPtr(count++);
DriverHandles.Add(driver_handle, this);
SDL.AddEventWatch(EventFilterDelegate, driver_handle);
@@ -188,7 +190,7 @@ void Dispose(bool manual)
joystick_driver.Dispose();
lock (SDL.Sync)
{
- SDL.DelEventWatch(EventFilterDelegate, IntPtr.Zero);
+ SDL.DelEventWatch(EventFilterDelegate, driver_handle);
}
DriverHandles.Remove(driver_handle);
}
View
4 Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs
@@ -59,7 +59,8 @@ class Sdl2NativeWindow : INativeWindow, IInputDriver
readonly IInputDriver input_driver = new Sdl2InputDriver();
- readonly EventFilter EventFilterDelegate = FilterEvents;
+ readonly EventFilter EventFilterDelegate_GCUnsafe = FilterEvents;
+ readonly IntPtr EventFilterDelegate;
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
new Dictionary<uint, Sdl2NativeWindow>();
@@ -85,6 +86,7 @@ class Sdl2NativeWindow : INativeWindow, IInputDriver
IntPtr handle;
lock (SDL.Sync)
{
+ EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
SDL.AddEventWatch(EventFilterDelegate, handle);
SDL.PumpEvents();
Please sign in to comment.
Something went wrong with that request. Please try again.