godot icon indicating copy to clipboard operation
godot copied to clipboard

TextEdit caret line selection raises: Index p_column = N is out of bounds

Open andreymal opened this issue 2 years ago • 4 comments

Godot version

4.0.beta17

System information

Linux

Issue description

This issue is very similar to #69011 and #69055 but I ran into this error in latest beta.

scene/gui/text_edit.cpp:4943 - Index p_column = 6 is out of bounds (text[carets[p_caret].selection.selecting_line].length() + 1 = 6).

Steps to reproduce

  1. Open the script editor
  2. Select any line
  3. Press Tab to indent this line
  4. Remove selection
  5. Select the line again
  6. Press Shift+Tab to unindent
  7. Click after the end of the line
  8. The error happens

godot-out-of-bounds

Minimal reproduction project

not needed

andreymal avatar Feb 06 '23 15:02 andreymal

The same error happens when using "Convert Indent to Tabs" instead of indent/unindent (but I'm too lazy to make another gif). I think it always happens when the selected line gets shorter

andreymal avatar Feb 06 '23 15:02 andreymal

CC @Paulb23 @KoBeWi

akien-mga avatar Feb 06 '23 16:02 akien-mga

Working on it. There's more to this bug than meets the eye, though I'm not going to open separate bug reports. If someone else wants to work on this now, please poke me so I can explain, I'll keep trying to solve it myself for now

MewPurPur avatar Feb 16 '23 06:02 MewPurPur

I explained what causes the bug and a possible easy patch in the PR above. Though right now, I'm trying to rework the TextEdit selection system to be simpler and less bug-prone.

MewPurPur avatar Mar 08 '23 17:03 MewPurPur

Can you still reproduce this in 4.0.3 and 4.1-beta3 or later?

akien-mga avatar Jun 23 '23 16:06 akien-mga

@akien-mga yes

Screenshot_20230623_191843

andreymal avatar Jun 23 '23 16:06 andreymal

Yeah, nothing about the underlying problems was solved. Text selection still needs an overhaul and to consistently be updated when text with selections is moved.

MewPurPur avatar Jun 23 '23 19:06 MewPurPur

I found another way this happens:

  1. Select text
  2. Toggle Comment
  3. Deselect
  4. Select again
  5. Toggle Comment
  6. Click at the end

I'm running v4.1.rc1.official [1f9e540f1]

error

NOTE: Even though I'm demonstrating at the end of the script, the same happens if I do it anywhere in the middle of the script.

Also, I believe https://github.com/godotengine/godot/issues/74400 is the same issue.

See also: https://github.com/godotengine/godot/issues/69011 and https://github.com/godotengine/godot/issues/67828

theraot avatar Jun 30 '23 08:06 theraot

Yeah, everything that can remove characters from a line while its end is selected would have this issue; untoggling comments is one of those things. Again, the PR I made above that was closed explains it, it's just hard to solve. Me and Paulb seem to have settled down on needing to rework the whole text selection system of TextEdit to rely on less information and to update said information more consistently, since the problem is that when a line is updated, we don't update the "pivot" of the selection.

Ideally, the pivot should be a bool saying if it's the beginning or the end of the selection, which would make it impossible that it goes to an invalid position. I'm looking to make this change in LineEdit first - I started it, but got burned out with the script editor :sweat: still on my plans, hopefully I can make the refactor for 4.2

MewPurPur avatar Jun 30 '23 08:06 MewPurPur