Unhandled Exception when rapidly switching between pens when drawing
See original GitHub issueReproduction steps:
When the hotkeys for pens and strokes are being made in rapid succession, this leads to an uncaught exception, which probably could safely be caught, as an alternative to a window which if you click 2 out of 3 buttons exits the application and might scare non-technical users.
`UIThreadException
Oops, gInk crashed! Please include the following information if you plan to contact the developers (a copy of the following information is stored in crash.txt in the application folder):
The operation cannot be performed while the object or control collects or recognizes ink.
Stack Trace: at Microsoft.Ink.InkErrors.ThrowExceptionForInkError(Int32 error) at Microsoft.Ink.InkOverlay.SetWindowInputRectangle(Rectangle windowInputRectangle) at gInk.FormCollection.SelectPen(Int32 pen) in C:\Geovens\gInk\src\FormCollection.cs:line 681 at gInk.FormCollection.tiSlide_Tick(Object sender, EventArgs e) in C:\Geovens\gInk\src\FormCollection.cs:line 1078 at System.Windows.Forms.Timer.OnTick(EventArgs e) at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)`
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
@geovens As for the parsing
This has to do with the CultureInfo setting of the Thread or the one that is implicitly used by the Parse and ToString overloads used in
ReadOptions
andSaveOptions
Consider this code:
And its result:
The best way to avoid such ambiguity is to be explicit in the parse itself (i.e. where the values are read and written from context, as per
Console.WriteLine($"US interpretation explicit parse call: {double.Parse(value, CultureInfo.InvariantCulture)}");
Although an easy program-wide fix is to do
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
As for the error with switching pens, I have a good fix in mind, this will make unnecessary setting of the SetWindowInputRectangle obsolete; simply use this property:
in this type of code:
It may be that it no longer is possible at all to produce the exception, working with this technique I cannot reproduce the issue no matter how hard I try, without requiring ugly locks or complicated means. Switching between pen 1 and pen 2 for example; there is no need to call
IC.SetWindowInputRectangle(new Rectangle(0, 0, this.Width, this.Height));
a second time 😃@geovens: Should I do a pull request for handling the Exception? And/or for a proposed improvement in file handling? I also discovered another bug there, the pan_enabled setting is wrongly saved or consumed I believe, looks to be a simple copy paste error 😃
Thank you for the report. As I can’t reproduce this crash and it may be complicated to properly fix this, I will simply catch the exception now in hope to make the crash even more rare.