Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andreymal opened this issue Feb 6, 2023 · 9 comments · Fixed by #86978
Closed

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

andreymal opened this issue Feb 6, 2023 · 9 comments · Fixed by #86978

Comments

@andreymal
Copy link

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

@akien-mga akien-mga changed the title Index p_column = N is out of bounds TextEdit caret line selection raises: Index p_column = N is out of bounds Feb 6, 2023
@akien-mga akien-mga added this to the 4.0 milestone Feb 6, 2023
@andreymal
Copy link
Author

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

@akien-mga
Copy link
Member

CC @Paulb23 @KoBeWi

@MewPurPur
Copy link
Contributor

MewPurPur commented Feb 16, 2023

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
Copy link
Contributor

MewPurPur commented Mar 8, 2023

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.

@akien-mga
Copy link
Member

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

@akien-mga akien-mga modified the milestones: 4.1, 4.2 Jun 23, 2023
@andreymal
Copy link
Author

@akien-mga yes

Screenshot_20230623_191843

@MewPurPur
Copy link
Contributor

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.

@theraot
Copy link
Contributor

theraot commented Jun 30, 2023

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 [1f9e540]

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 #74400 is the same issue.

See also: #69011 and #67828

@MewPurPur
Copy link
Contributor

MewPurPur commented Jun 30, 2023

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 😓 still on my plans, hopefully I can make the refactor for 4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants