mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-09-23 21:57:10 +00:00
Serialize Sdl2NativeWindow methods
This change, along with moving DestroyWindow() to the Dispose() method fixes crashes on shutdown.
This commit is contained in:
parent
3c867838e6
commit
f2eda16458
|
@ -38,6 +38,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
class Sdl2NativeWindow : INativeWindow, IInputDriver
|
class Sdl2NativeWindow : INativeWindow, IInputDriver
|
||||||
{
|
{
|
||||||
|
readonly object sync = new object();
|
||||||
|
|
||||||
Sdl2WindowInfo window;
|
Sdl2WindowInfo window;
|
||||||
uint window_id;
|
uint window_id;
|
||||||
bool is_visible;
|
bool is_visible;
|
||||||
|
@ -65,6 +67,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
public Sdl2NativeWindow(int x, int y, int width, int height,
|
public Sdl2NativeWindow(int x, int y, int width, int height,
|
||||||
string title, GameWindowFlags options, DisplayDevice device)
|
string title, GameWindowFlags options, DisplayDevice device)
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
{
|
{
|
||||||
var bounds = device.Bounds;
|
var bounds = device.Bounds;
|
||||||
var flags = TranslateFlags(options);
|
var flags = TranslateFlags(options);
|
||||||
|
@ -79,31 +83,29 @@ namespace OpenTK.Platform.SDL2
|
||||||
lock (SDL.Sync)
|
lock (SDL.Sync)
|
||||||
{
|
{
|
||||||
handle = SDL.SDL_CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
handle = SDL.SDL_CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
||||||
|
SDL.SDL_AddEventWatch(EventFilterDelegate, handle);
|
||||||
|
SDL.SDL_PumpEvents();
|
||||||
}
|
}
|
||||||
window = new Sdl2WindowInfo(handle, null);
|
window = new Sdl2WindowInfo(handle, null);
|
||||||
window_id = SDL.SDL_GetWindowID(handle);
|
window_id = SDL.SDL_GetWindowID(handle);
|
||||||
windows.Add(window_id, this);
|
windows.Add(window_id, this);
|
||||||
window_title = title;
|
window_title = title;
|
||||||
|
|
||||||
keyboard.Description = "Standard Windows keyboard";
|
keyboard.Description = "Standard keyboard";
|
||||||
keyboard.NumberOfFunctionKeys = 12;
|
keyboard.NumberOfFunctionKeys = 12;
|
||||||
keyboard.NumberOfKeys = 101;
|
keyboard.NumberOfKeys = 101;
|
||||||
keyboard.NumberOfLeds = 3;
|
keyboard.NumberOfLeds = 3;
|
||||||
|
|
||||||
mouse.Description = "Standard Windows mouse";
|
mouse.Description = "Standard mouse";
|
||||||
mouse.NumberOfButtons = 3;
|
mouse.NumberOfButtons = 3;
|
||||||
mouse.NumberOfWheels = 1;
|
mouse.NumberOfWheels = 1;
|
||||||
|
|
||||||
keyboards.Add(keyboard);
|
keyboards.Add(keyboard);
|
||||||
mice.Add(mouse);
|
mice.Add(mouse);
|
||||||
|
|
||||||
lock (SDL.Sync)
|
|
||||||
{
|
|
||||||
SDL.SDL_AddEventWatch(EventFilterDelegate, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
exists = true;
|
exists = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Private Members
|
#region Private Members
|
||||||
|
|
||||||
|
@ -141,7 +143,6 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
Sdl2NativeWindow window = null;
|
Sdl2NativeWindow window = null;
|
||||||
SDL.SDL_Event ev = *(SDL.SDL_Event*)e;
|
SDL.SDL_Event ev = *(SDL.SDL_Event*)e;
|
||||||
|
|
||||||
|
@ -190,12 +191,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL.SDL_EventType.SDL_QUIT:
|
case SDL.SDL_EventType.SDL_QUIT:
|
||||||
/*
|
Debug.WriteLine("Sdl2 application quit");
|
||||||
if (windows.TryGetValue(ev.quit.windowID, out window))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +266,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
if (!close_args.Cancel)
|
if (!close_args.Cancel)
|
||||||
{
|
{
|
||||||
window.Closed(window, EventArgs.Empty);
|
window.Closed(window, EventArgs.Empty);
|
||||||
window.DestroyWindow();
|
//window.DestroyWindow();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -346,12 +342,12 @@ namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
lock (SDL.Sync)
|
lock (SDL.Sync)
|
||||||
{
|
{
|
||||||
SDL.SDL_DestroyWindow(window.Handle);
|
|
||||||
SDL.SDL_DelEventWatch(EventFilterDelegate, window.Handle);
|
SDL.SDL_DelEventWatch(EventFilterDelegate, window.Handle);
|
||||||
if (windows.ContainsKey(window_id))
|
if (windows.ContainsKey(window_id))
|
||||||
{
|
{
|
||||||
windows.Remove(window_id);
|
windows.Remove(window_id);
|
||||||
}
|
}
|
||||||
|
SDL.SDL_DestroyWindow(window.Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,12 +421,14 @@ namespace OpenTK.Platform.SDL2
|
||||||
public event EventHandler<EventArgs> MouseLeave = delegate { };
|
public event EventHandler<EventArgs> MouseLeave = delegate { };
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
{
|
{
|
||||||
if (Exists)
|
if (Exists)
|
||||||
{
|
{
|
||||||
Debug.Print("SDL2 destroying window {0}", window.Handle);
|
Debug.Print("SDL2 destroying window {0}", window.Handle);
|
||||||
|
|
||||||
SDL.SDL_Event e = new SDL.SDL_Event();
|
SDL.SDL_Event e = new SDL.SDL_Event();
|
||||||
//e.type = SDL.SDL_EventType.SDL_QUIT;
|
|
||||||
e.type = SDL.SDL_EventType.SDL_WINDOWEVENT;
|
e.type = SDL.SDL_EventType.SDL_WINDOWEVENT;
|
||||||
e.window.windowEvent = SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE;
|
e.window.windowEvent = SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE;
|
||||||
e.window.windowID = window_id;
|
e.window.windowID = window_id;
|
||||||
|
@ -440,12 +438,13 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ProcessEvents()
|
public void ProcessEvents()
|
||||||
{
|
{
|
||||||
if (Exists)
|
lock (sync)
|
||||||
{
|
{
|
||||||
lock (SDL.Sync)
|
if (Exists)
|
||||||
{
|
{
|
||||||
SDL.SDL_PumpEvents();
|
SDL.SDL_PumpEvents();
|
||||||
}
|
}
|
||||||
|
@ -473,6 +472,10 @@ namespace OpenTK.Platform.SDL2
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
// Set the new icon, if any, or clear the current
|
// Set the new icon, if any, or clear the current
|
||||||
// icon if null
|
// icon if null
|
||||||
|
@ -509,19 +512,34 @@ namespace OpenTK.Platform.SDL2
|
||||||
IconChanged(this, EventArgs.Empty);
|
IconChanged(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string Title
|
public string Title
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
return SDL.SDL_GetWindowTitle(window.Handle);
|
return SDL.SDL_GetWindowTitle(window.Handle);
|
||||||
}
|
}
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
SDL.SDL_SetWindowTitle(window.Handle, value);
|
SDL.SDL_SetWindowTitle(window.Handle, value);
|
||||||
window_title = value;
|
window_title = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Focused
|
public bool Focused
|
||||||
{
|
{
|
||||||
|
@ -538,6 +556,10 @@ namespace OpenTK.Platform.SDL2
|
||||||
return is_visible;
|
return is_visible;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
SDL.SDL_ShowWindow(window.Handle);
|
SDL.SDL_ShowWindow(window.Handle);
|
||||||
|
@ -545,6 +567,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
SDL.SDL_HideWindow(window.Handle);
|
SDL.SDL_HideWindow(window.Handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Exists
|
public bool Exists
|
||||||
{
|
{
|
||||||
|
@ -570,11 +594,12 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (WindowState == value)
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
|
{
|
||||||
|
if (WindowState != value)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the new WindowState
|
// Set the new WindowState
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
|
@ -612,6 +637,9 @@ namespace OpenTK.Platform.SDL2
|
||||||
GrabCursor(true);
|
GrabCursor(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public WindowBorder WindowBorder
|
public WindowBorder WindowBorder
|
||||||
{
|
{
|
||||||
|
@ -621,8 +649,13 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value != WindowBorder)
|
if (WindowBorder != value)
|
||||||
{
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
|
{
|
||||||
|
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
case WindowBorder.Resizable:
|
case WindowBorder.Resizable:
|
||||||
|
@ -639,11 +672,16 @@ namespace OpenTK.Platform.SDL2
|
||||||
Debug.WriteLine("SDL2 cannot change to fixed-size windows at runtime.");
|
Debug.WriteLine("SDL2 cannot change to fixed-size windows at runtime.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Exists)
|
||||||
|
{
|
||||||
WindowBorderChanged(this, EventArgs.Empty);
|
WindowBorderChanged(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Rectangle Bounds
|
public Rectangle Bounds
|
||||||
{
|
{
|
||||||
|
@ -661,30 +699,56 @@ namespace OpenTK.Platform.SDL2
|
||||||
public Point Location
|
public Point Location
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
SDL.SDL_GetWindowPosition(window.Handle, out x, out y);
|
SDL.SDL_GetWindowPosition(window.Handle, out x, out y);
|
||||||
return new Point(x, y);
|
return new Point(x, y);
|
||||||
}
|
}
|
||||||
|
return new Point();
|
||||||
|
}
|
||||||
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
SDL.SDL_SetWindowPosition(window.Handle, value.X, value.Y);
|
SDL.SDL_SetWindowPosition(window.Handle, value.X, value.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Size Size
|
public Size Size
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL.SDL_GetWindowSize(window.Handle, out w, out h);
|
SDL.SDL_GetWindowSize(window.Handle, out w, out h);
|
||||||
return new Size(w, h);
|
return new Size(w, h);
|
||||||
}
|
}
|
||||||
|
return new Size();
|
||||||
|
}
|
||||||
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
SDL.SDL_SetWindowSize(window.Handle, value.Width, value.Height);
|
SDL.SDL_SetWindowSize(window.Handle, value.Width, value.Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int X
|
public int X
|
||||||
{
|
{
|
||||||
|
@ -777,11 +841,17 @@ namespace OpenTK.Platform.SDL2
|
||||||
return is_cursor_visible;
|
return is_cursor_visible;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
{
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
|
if (Exists)
|
||||||
{
|
{
|
||||||
GrabCursor(!value);
|
GrabCursor(!value);
|
||||||
is_cursor_visible = value;
|
is_cursor_visible = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -789,7 +859,6 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
public void Poll()
|
public void Poll()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -839,11 +908,14 @@ namespace OpenTK.Platform.SDL2
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
Debug.Print("Disposing {0}", GetType());
|
Debug.Print("Disposing {0}", GetType());
|
||||||
|
lock (sync)
|
||||||
|
{
|
||||||
if (Exists)
|
if (Exists)
|
||||||
{
|
{
|
||||||
DestroyWindow();
|
DestroyWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Sdl2NativeWindow leaked, did you forget to call Dispose()?");
|
Debug.WriteLine("Sdl2NativeWindow leaked, did you forget to call Dispose()?");
|
||||||
|
|
Loading…
Reference in a new issue