mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 18:15:38 +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,9 +236,12 @@ namespace OpenTK.Platform.Windows
|
|||
break;
|
||||
}
|
||||
|
||||
lock (UpdateLock)
|
||||
{
|
||||
keyboards[rawids[handle]] = keyboard;
|
||||
return processed;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -263,6 +267,8 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
|
||||
public KeyboardState GetState()
|
||||
{
|
||||
lock (UpdateLock)
|
||||
{
|
||||
KeyboardState master = new KeyboardState();
|
||||
foreach (KeyboardState ks in keyboards)
|
||||
|
@ -271,14 +277,18 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
return master;
|
||||
}
|
||||
}
|
||||
|
||||
public KeyboardState GetState(int index)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -64,6 +65,8 @@ namespace OpenTK.Platform.Windows
|
|||
public IList<MouseDevice> Mouse { get { throw new NotImplementedException(); } }
|
||||
|
||||
public MouseState GetState()
|
||||
{
|
||||
lock (UpdateLock)
|
||||
{
|
||||
MouseState master = new MouseState();
|
||||
foreach (MouseState ms in mice)
|
||||
|
@ -72,14 +75,18 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
return master;
|
||||
}
|
||||
}
|
||||
|
||||
public MouseState GetState(int index)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
lock (UpdateLock)
|
||||
{
|
||||
mice[rawids[handle]] = mouse;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue