mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-03-27 05:35:13 +00:00
Protect against recursion in Closing event
Misbehaving clients that shall not be named here may call GameWindow.Close() inside the GameWindow.Closing event. This causes recursion in SDL2, crashing the application. This patch adds a guard to protect against recursion when calling GameWindow.Close().
This commit is contained in:
parent
39a216f1ac
commit
1392d48ec0
|
@ -53,6 +53,7 @@ namespace OpenTK.Platform.SDL2
|
|||
bool exists;
|
||||
bool must_destroy;
|
||||
bool disposed;
|
||||
volatile bool is_in_closing_event;
|
||||
WindowState window_state = WindowState.Normal;
|
||||
WindowState previous_window_state = WindowState.Normal;
|
||||
WindowBorder window_border = WindowBorder.Resizable;
|
||||
|
@ -303,7 +304,16 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
case WindowEventID.CLOSE:
|
||||
var close_args = new System.ComponentModel.CancelEventArgs();
|
||||
window.Closing(window, close_args);
|
||||
try
|
||||
{
|
||||
window.is_in_closing_event = true;
|
||||
window.Closing(window, close_args);
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.is_in_closing_event = false;
|
||||
}
|
||||
|
||||
if (!close_args.Cancel)
|
||||
{
|
||||
window.Closed(window, EventArgs.Empty);
|
||||
|
@ -463,7 +473,7 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
lock (sync)
|
||||
{
|
||||
if (Exists && !must_destroy)
|
||||
if (Exists && !must_destroy && !is_in_closing_event)
|
||||
{
|
||||
Debug.Print("SDL2 closing window {0}", window.Handle);
|
||||
|
||||
|
|
Loading…
Reference in a new issue