question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unhandled Exception when rapidly switching between pens when drawing

See original GitHub issue

Reproduction 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:open
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Joeppiecommented, Apr 26, 2020

@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 and SaveOptions

Consider this code:

        string value = "0.06";
        Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("NL-nl");
        Console.WriteLine($"Dutch interpretation: {double.Parse(value)}");

        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        Console.WriteLine($"US interpretation: {double.Parse(value)}");

And its result:

image

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)}");

image

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:

    private bool _interactWithInk;
    /// <summary>Whether or not the canvas can collect ink or not.</summary>
    public bool InteractWithInk
    {
        get { return _interactWithInk; }
        set
        {
            if (_interactWithInk)
            {
                if (_interactWithInk != value) //turn off ink, but only do so if it's not already off.
                {
                    IC.SetWindowInputRectangle(new Rectangle(0, 0, 1, 1));
                }
            }
            else
            {
                if (_interactWithInk != value) //turn on ink, but do so only if it's not already on.
                {
                    IC.SetWindowInputRectangle(new Rectangle(0, 0, this.Width, this.Height));
                }
            }
            _interactWithInk = value; //Apply value.
        }
    }

in this type of code:

     try
                {
                    InteractWithInk = true;
                }
                catch
                {
                    Thread.Sleep(1);
                    InteractWithInk = true;
                }

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 😃

1reaction
geovenscommented, Apr 16, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception while drawing text · Issue #34
Unhandled exception. SixLabors.ImageSharp.ImageProcessingException: An error occurred when processing the image using DrawTextProcessor`1.
Read more >
How to Fix Pen Drawing on Wrong Monitor in ... - YouTube
For me my pen would draw on a different monitor when trying to draw on my art tablet. ... See all Clip Studio...
Read more >
Unhandled exception
I am continuously getting an "unhandled exception" error code . This drawing represents a portion of an older drawing that also crashes upon ......
Read more >
Drawboard PDF: Release Notes - Windows app
Fix for a pen issue that can stop the pen drawing after scrolling in some circumstances. Version 5.37.2. Released on 13/05/2021. Bug fixes....
Read more >
How to set drawing automatically when using pen in ...
Have a look in the Advanced Options and make sure that the option "Automatically switch between inking, selection, typing, and panning" is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found