summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release-notes.md1
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs18
2 files changed, 16 insertions, 3 deletions
diff --git a/release-notes.md b/release-notes.md
index ae2f853d..b1917ef7 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -22,6 +22,7 @@ For players:
* `list_items` now also matches translated item names when playing in another language.
* `list_item_types` is a new command to see a list of item types.
* Added clearer error when a `config.json` is invalid.
+* Fixed rare crash when window loses focus for a few players (further to fix in 1.14).
For modders:
* You can now specify minimum dependency versions in `manifest.json`.
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs
index 80ae20ac..39713d4a 100644
--- a/src/StardewModdingAPI/Framework/SGame.cs
+++ b/src/StardewModdingAPI/Framework/SGame.cs
@@ -344,9 +344,21 @@ namespace StardewModdingAPI.Framework
if (Game1.game1.IsActive)
{
// get latest state
- KeyboardState keyState = Keyboard.GetState();
- MouseState mouseState = Mouse.GetState();
- Point mousePosition = new Point(Game1.getMouseX(), Game1.getMouseY());
+ KeyboardState keyState;
+ MouseState mouseState;
+ Point mousePosition;
+ try
+ {
+ keyState = Keyboard.GetState();
+ mouseState = Mouse.GetState();
+ mousePosition = new Point(Game1.getMouseX(), Game1.getMouseY());
+ }
+ catch (InvalidOperationException) // GetState() may crash for some players if window doesn't have focus but game1.IsActive == true
+ {
+ keyState = this.PreviousKeyState;
+ mouseState = this.PreviousMouseState;
+ mousePosition = this.PreviousMousePosition;
+ }
// analyse state
Keys[] currentlyPressedKeys = keyState.GetPressedKeys();