mitigate the intermittent crash while handling the keyboard/mouse inputs by adding the try/catch block

this is a temporary fix before I can figure out the root cause of the failure. Changed the keyboard/mouse
data-structure to be Queue rather than Stack so keyboard/mouse inputs are ingested in order.
master
Zaafar Ahmed 5 years ago
parent 5f2474b1eb
commit ccf1065ff9
  1. 20
      ClickableTransparentOverlay/HookController.cs

@ -21,7 +21,7 @@ namespace ClickableTransparentOverlay
/// </summary> /// </summary>
public class HookController public class HookController
{ {
private readonly Stack<HookControllerMessage> messages; private readonly Queue<HookControllerMessage> messages;
private IKeyboardMouseEvents myHook; private IKeyboardMouseEvents myHook;
private bool enable; private bool enable;
private int windowX; private int windowX;
@ -38,7 +38,7 @@ namespace ClickableTransparentOverlay
/// </param> /// </param>
public HookController(int x, int y) public HookController(int x, int y)
{ {
this.messages = new Stack<HookControllerMessage>(); this.messages = new Queue<HookControllerMessage>();
this.windowX = x; this.windowX = x;
this.windowY = y; this.windowY = y;
this.enable = true; this.enable = true;
@ -127,10 +127,12 @@ namespace ClickableTransparentOverlay
public void PopMessages() public void PopMessages()
{ {
int counter = 0; int counter = 0;
int maxCounter = 10; int maxCounter = 20;
while (counter < maxCounter && this.messages.Count > 0) while (counter < maxCounter && this.messages.Count > 0)
{ {
var message = this.messages.Pop(); var message = this.messages.Dequeue();
try
{
switch (message.Type) switch (message.Type)
{ {
case HookControllerMessageType.MouseUpDown: case HookControllerMessageType.MouseUpDown:
@ -154,6 +156,14 @@ namespace ClickableTransparentOverlay
default: default:
break; break;
} }
}
catch (Exception e)
{
Console.WriteLine("Warning: Caught an exception while handling keyboard/mouse inputs." +
"Report to the GitHub repository if this effects your work & it's reproduceable.");
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
counter++; counter++;
} }
@ -180,7 +190,7 @@ namespace ClickableTransparentOverlay
MiscArg = miscArg, MiscArg = miscArg,
}; };
this.messages.Push(message); this.messages.Enqueue(message);
} }
private void ProcessMouseUpDown(MouseEventExtArgs e, bool isDownEvent, bool shouldSendToImGui) private void ProcessMouseUpDown(MouseEventExtArgs e, bool isDownEvent, bool shouldSendToImGui)

Loading…
Cancel
Save