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.
This commit is contained in:
parent
255f4e9083
commit
48803bb4d6
3 changed files with 15 additions and 3 deletions
|
@ -83,6 +83,10 @@ namespace OpenTK.Platform.SDL2
|
|||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_AddEventWatch", ExactSpelling = true)]
|
||||
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,
|
||||
|
@ -102,6 +106,10 @@ namespace OpenTK.Platform.SDL2
|
|||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_DelEventWatch", ExactSpelling = true)]
|
||||
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);
|
||||
|
|
|
@ -45,7 +45,8 @@ namespace OpenTK.Platform.SDL2
|
|||
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 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
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 @@ namespace OpenTK.Platform.SDL2
|
|||
joystick_driver.Dispose();
|
||||
lock (SDL.Sync)
|
||||
{
|
||||
SDL.DelEventWatch(EventFilterDelegate, IntPtr.Zero);
|
||||
SDL.DelEventWatch(EventFilterDelegate, driver_handle);
|
||||
}
|
||||
DriverHandles.Remove(driver_handle);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,8 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
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 @@ namespace OpenTK.Platform.SDL2
|
|||
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();
|
||||
|
|
Loading…
Reference in a new issue