mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 02:45:36 +00:00
Do not modify device state during the GetState() call. Fixes intermittent crashes.
This commit is contained in:
parent
03c97e306b
commit
c1043d1693
|
@ -46,6 +46,7 @@ namespace OpenTK.Platform.Windows
|
|||
readonly Dictionary<ContextHandle, int> rawids = new Dictionary<ContextHandle, int>();
|
||||
private List<KeyboardDevice> keyboards_old = new List<KeyboardDevice>();
|
||||
private IntPtr window;
|
||||
readonly object UpdateLock = new object();
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
|
@ -235,8 +236,11 @@ namespace OpenTK.Platform.Windows
|
|||
break;
|
||||
}
|
||||
|
||||
keyboards[rawids[handle]] = keyboard;
|
||||
return processed;
|
||||
lock (UpdateLock)
|
||||
{
|
||||
keyboards[rawids[handle]] = keyboard;
|
||||
return processed;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -264,20 +268,26 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
public KeyboardState GetState()
|
||||
{
|
||||
KeyboardState master = new KeyboardState();
|
||||
foreach (KeyboardState ks in keyboards)
|
||||
lock (UpdateLock)
|
||||
{
|
||||
master.MergeBits(ks);
|
||||
KeyboardState master = new KeyboardState();
|
||||
foreach (KeyboardState ks in keyboards)
|
||||
{
|
||||
master.MergeBits(ks);
|
||||
}
|
||||
return master;
|
||||
}
|
||||
return master;
|
||||
}
|
||||
|
||||
public KeyboardState GetState(int index)
|
||||
{
|
||||
if (keyboards.Count > index)
|
||||
return keyboards[index];
|
||||
else
|
||||
return new KeyboardState();
|
||||
lock (UpdateLock)
|
||||
{
|
||||
if (keyboards.Count > index)
|
||||
return keyboards[index];
|
||||
else
|
||||
return new KeyboardState();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -44,6 +44,7 @@ namespace OpenTK.Platform.Windows
|
|||
List<MouseState> mice;
|
||||
Dictionary<ContextHandle, int> rawids; // ContextHandle instead of IntPtr for fast dictionary access
|
||||
readonly IntPtr Window;
|
||||
readonly object UpdateLock = new object();
|
||||
|
||||
public WinRawMouse(IntPtr window)
|
||||
{
|
||||
|
@ -65,20 +66,26 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
public MouseState GetState()
|
||||
{
|
||||
MouseState master = new MouseState();
|
||||
foreach (MouseState ms in mice)
|
||||
lock (UpdateLock)
|
||||
{
|
||||
master.MergeBits(ms);
|
||||
MouseState master = new MouseState();
|
||||
foreach (MouseState ms in mice)
|
||||
{
|
||||
master.MergeBits(ms);
|
||||
}
|
||||
return master;
|
||||
}
|
||||
return master;
|
||||
}
|
||||
|
||||
public MouseState GetState(int index)
|
||||
{
|
||||
if (mice.Count > index)
|
||||
return mice[index];
|
||||
else
|
||||
return new MouseState();
|
||||
lock (UpdateLock)
|
||||
{
|
||||
if (mice.Count > index)
|
||||
return mice[index];
|
||||
else
|
||||
return new MouseState();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -226,8 +233,11 @@ namespace OpenTK.Platform.Windows
|
|||
mouse.Y += raw.LastY;
|
||||
}
|
||||
|
||||
mice[rawids[handle]] = mouse;
|
||||
return true;
|
||||
lock (UpdateLock)
|
||||
{
|
||||
mice[rawids[handle]] = mouse;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue