mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 15:35:34 +00:00
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
|
@ -83,6 +83,10 @@ namespace OpenTK.Platform.SDL2
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_AddEventWatch", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_AddEventWatch", ExactSpelling = true)]
|
||||||
public static extern void AddEventWatch(EventFilter filter, IntPtr userdata);
|
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]
|
[SuppressUnmanagedCodeSecurity]
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_CreateRGBSurfaceFrom", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_CreateRGBSurfaceFrom", ExactSpelling = true)]
|
||||||
public static extern IntPtr CreateRGBSurfaceFrom(IntPtr pixels,
|
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)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_DelEventWatch", ExactSpelling = true)]
|
||||||
public static extern void DelEventWatch(EventFilter filter, IntPtr userdata);
|
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]
|
[SuppressUnmanagedCodeSecurity]
|
||||||
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_DestroyWindow", ExactSpelling = true)]
|
[DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_DestroyWindow", ExactSpelling = true)]
|
||||||
public static extern void DestroyWindow(IntPtr window);
|
public static extern void DestroyWindow(IntPtr window);
|
||||||
|
|
|
@ -45,7 +45,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
readonly Sdl2Mouse mouse_driver = new Sdl2Mouse();
|
readonly Sdl2Mouse mouse_driver = new Sdl2Mouse();
|
||||||
readonly Sdl2JoystickDriver joystick_driver = new Sdl2JoystickDriver();
|
readonly Sdl2JoystickDriver joystick_driver = new Sdl2JoystickDriver();
|
||||||
|
|
||||||
readonly EventFilter EventFilterDelegate = FilterInputEvents;
|
readonly EventFilter EventFilterDelegate_GCUnsafe = FilterInputEvents;
|
||||||
|
readonly IntPtr EventFilterDelegate;
|
||||||
|
|
||||||
static int count;
|
static int count;
|
||||||
bool disposed;
|
bool disposed;
|
||||||
|
@ -54,6 +55,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
lock (SDL.Sync)
|
lock (SDL.Sync)
|
||||||
{
|
{
|
||||||
|
EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
|
||||||
driver_handle = new IntPtr(count++);
|
driver_handle = new IntPtr(count++);
|
||||||
DriverHandles.Add(driver_handle, this);
|
DriverHandles.Add(driver_handle, this);
|
||||||
SDL.AddEventWatch(EventFilterDelegate, driver_handle);
|
SDL.AddEventWatch(EventFilterDelegate, driver_handle);
|
||||||
|
@ -188,7 +190,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
joystick_driver.Dispose();
|
joystick_driver.Dispose();
|
||||||
lock (SDL.Sync)
|
lock (SDL.Sync)
|
||||||
{
|
{
|
||||||
SDL.DelEventWatch(EventFilterDelegate, IntPtr.Zero);
|
SDL.DelEventWatch(EventFilterDelegate, driver_handle);
|
||||||
}
|
}
|
||||||
DriverHandles.Remove(driver_handle);
|
DriverHandles.Remove(driver_handle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
readonly IInputDriver input_driver = new Sdl2InputDriver();
|
readonly IInputDriver input_driver = new Sdl2InputDriver();
|
||||||
|
|
||||||
readonly EventFilter EventFilterDelegate = FilterEvents;
|
readonly EventFilter EventFilterDelegate_GCUnsafe = FilterEvents;
|
||||||
|
readonly IntPtr EventFilterDelegate;
|
||||||
|
|
||||||
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
|
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
|
||||||
new Dictionary<uint, Sdl2NativeWindow>();
|
new Dictionary<uint, Sdl2NativeWindow>();
|
||||||
|
@ -85,6 +86,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
IntPtr handle;
|
IntPtr handle;
|
||||||
lock (SDL.Sync)
|
lock (SDL.Sync)
|
||||||
{
|
{
|
||||||
|
EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
|
||||||
handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
||||||
SDL.AddEventWatch(EventFilterDelegate, handle);
|
SDL.AddEventWatch(EventFilterDelegate, handle);
|
||||||
SDL.PumpEvents();
|
SDL.PumpEvents();
|
||||||
|
|
Loading…
Reference in a new issue