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.

View crashes when trying to get seleciton when last char is " "

See original GitHub issue

How to reproduce: Set last char of TextField (or ComboBox or maybe other views) text to " " then double click at next position.

Reproduceable both on main and nuget version. PrepareSelection method passes invalid parameters to String.SubString resulting an exception.

As I’ve understood, selection tries to ignore whitespace but there are some quircks, for example:

" abc " 
 ^ - if double click is called on first char then full string is selected


" abc " 
     ^ - if double click is called on last char "abc " is selected

" abc " 
      ^ - if double click is called on next after last char position then exception is thrown

It is easily reproduceable when the only char is " ". The code below then has start = 1 and length = 2 which results in exception. So I guess start = 1 is ok, but length of 2 is not. Considering text itself has 1 char only. image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
tznindcommented, Oct 2, 2021

Thanks for bringing this up. Here is a test that demonstrates it:

[Fact]
[InitShutdown]
public void TextField_SpaceHandling()
{
    var tf = new TextField(){
        Width = 10,
        Text = " "
    };

    MouseEvent ev = new MouseEvent()
    {
        X = 0,
        Y = 0,
        Flags = MouseFlags.Button1DoubleClicked,
    };

    tf.MouseEvent (ev);

    ev = new MouseEvent()
    {
        X = 1,
        Y = 0,
        Flags = MouseFlags.Button1DoubleClicked,
    };
    
    tf.MouseEvent (ev);
}

Exception:

dling [FAIL]
  Failed Terminal.Gui.Views.TextFieldTests.TextField_SpaceHandling [9 ms]
  Error Message:
   System.ArgumentOutOfRangeException : Index and length must refer to a location within the string. (Parameter 'length')
  Stack Trace:
     at System.String.Substring(Int32 startIndex, Int32 length)
   at Terminal.Gui.TextField.PrepareSelection(Int32 x, Int32 direction) in /home/thomas/gui.cs/Terminal.Gui/Views/TextField.cs:line 815
   at Terminal.Gui.TextField.MouseEvent(MouseEvent ev) in /home/thomas/gui.cs/Terminal.Gui/Views/TextField.cs:line 766
   at Terminal.Gui.Views.TextFieldTests.TextField_SpaceHandling() in /home/thomas/gui.cs/UnitTests/TextFieldTests.cs:line 815
2reactions
tigcommented, Oct 5, 2021

Damn, @tznind, you continue to set the bar for how to treat bug reports. I love how, by providing test cases, you are

a) teaching others how to fish b) ensuring the entire project is always getting better.

Huge kudos!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash on Character selection - Technical Support
Hi, My game crash after hit “play” on the character selection screen. I already verify the game and redownload it but no change....
Read more >
Game crashes after character select
I tried to relog and when I selected the character upon login I got the same warning message and the game crashed again....
Read more >
Game Crashes After Selecting Character : r/ffxiv
Now every time I try to pick my character, it crashes in the loading screen. r/ffxiv - Game Crashes After Selecting Character. I...
Read more >
Setting last character in a string to 0 causes program crash
You can not change a string literal. Character display with printf . E.g printf("%c", character); , not &character. try this.
Read more >
Game crashes when trying to select a specific character
Every character I have can load into the game successfully, but one specific one goes to the loading screen then the game crashes...
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