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

Index p_gutter = -1 is out of bounds error when saving file in external editor #81135

Closed
miv391 opened this issue Aug 29, 2023 · 13 comments · Fixed by #84907
Closed

Index p_gutter = -1 is out of bounds error when saving file in external editor #81135

miv391 opened this issue Aug 29, 2023 · 13 comments · Fixed by #84907

Comments

@miv391
Copy link
Contributor

miv391 commented Aug 29, 2023

Godot version

v4.2.dev3.official [013e8e3]

System information

Godot v4.2.dev3 - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 6GB (NVIDIA; 31.0.15.3640) - Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 Threads)

Issue description

You get these errors when saving file in external editor:

kuva

Godot Engine v4.2.dev3.official (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors.
--- Debug adapter server started ---
--- GDScript language server started ---
[LSP] Connection Taken
  scene/gui/text_edit.cpp:5900 - Index p_gutter = -1 is out of bounds (gutters.size() = 4).
  scene/gui/text_edit.cpp:5900 - Index p_gutter = -1 is out of bounds (gutters.size() = 4).
  scene/gui/text_edit.cpp:5900 - Index p_gutter = -1 is out of bounds (gutters.size() = 4).
  scene/gui/text_edit.cpp:5900 - Index p_gutter = -1 is out of bounds (gutters.size() = 4).
  scene/gui/text_edit.cpp:5900 - Index p_gutter = -1 is out of bounds (gutters.size() = 4).
  scene/gui/text_edit.cpp:5900 - Index p_gutter = -1 is out of bounds (gutters.size() = 4).

Steps to reproduce

Text Editor | Appearance | Highlight Type Safe Lines setting must be on.

My external editor is vscode version 1.18.1 with godot-tools version 1.3.1.

  1. Open attached minimal reproduction project (Project is created from a large project by chopping off stuff that didn't seem to affect the error.)
  2. Open stages.gd in vscode
  3. Press Ctrl-S to save stages.gd in vscode
  4. Change focus back to Godot

Sometimes the errors are displayed immediately after step 3, sometimes step 4 is needed.

Minimal reproduction project

I left some files in the .godot folder as I suspect that the editor layout might have something to do with the bug.

g42_p_gutter.zip

@ryanabx
Copy link
Contributor

ryanabx commented Sep 5, 2023

I can reproduce it on my personal project with Godot v4.2.dev (fcbd899b2) - Windows 10.0.22621 - GLES3 (Compatibility) - AMD Radeon(TM) Graphics (Advanced Micro Devices, Inc.; 31.0.21023.2010) - AMD Ryzen 9 6900HS with Radeon Graphics (16 Threads)

@YuriSizov YuriSizov added this to the 4.2 milestone Sep 5, 2023
@BNTFryingPan
Copy link
Contributor

can also reproduce on linux. using Godot v4.1.1.stable - Arch Linux #1 SMP PREEMPT_DYNAMIC Wed, 13 Sep 2023 08:37:40 +0000 - Vulkan (Compatibility) - Mesa Intel(R) Graphics (ADL GT2) () - 12th Gen Intel(R) Core(TM) i7-1260P (16 Threads)

@theraot
Copy link
Contributor

theraot commented Oct 6, 2023

Closing open scripts in the Godot editor seems to work around the error (i.e. no error spam when editing scripts in an external editor).

@Silabear
Copy link

Still a bug. Is this being worked on? It's quite annoying. :P

@miv391
Copy link
Contributor Author

miv391 commented Oct 13, 2023

Still happens with v4.2.dev6.official [57a6813]

scene/gui/text_edit.cpp:5889 - Index p_gutter = -1 is out of bounds (gutters.size() = 4).

I found out that if the "Highlight Type Safe Lines" editor setting is turned off, this bug doesn't happen.

kuva

This is the line mentioned in the error message (in master):

ERR_FAIL_INDEX(p_gutter, gutters.size());

The only suspicious calls to the function (set_line_gutter_item_color) where the error message is printed, are made from here:

te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
last_is_safe = true;
} else if (last_is_safe && (te->is_in_comment(i) != -1 || te->get_line(i).strip_edges().is_empty())) {
te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
} else {
te->set_line_gutter_item_color(i, line_number_gutter, default_line_number_color);
last_is_safe = false;
}
} else {
te->set_line_gutter_item_color(i, 1, default_line_number_color);
}

The default value of line_number_gutter is -1 and it seems it is never changed and we get the error.

This is the only place where line_number_gutter is changed:

void ScriptTextEditor::_update_gutter_indexes() {
for (int i = 0; i < code_editor->get_text_editor()->get_gutter_count(); i++) {
if (code_editor->get_text_editor()->get_gutter_name(i) == "connection_gutter") {
connection_gutter = i;
continue;
}
if (code_editor->get_text_editor()->get_gutter_name(i) == "line_numbers") {
line_number_gutter = i;
continue;
}
}
}

Either _update_gutter_indexes() is not called at all or it is called too late or for some reason it doesn't change line_number_gutter .

@MorningBeverage
Copy link

MorningBeverage commented Oct 30, 2023

I'm getting a similar issue, but instead of "gutter" it's "line"
scene/gui/text_edit.cpp:5300 - Index p_line = -1 is out of bounds (text.size() = 2).
un-checking "Highlight Type Safe" Lines doesn't prevent it from happening.

update: I've found that this one specifically happens upon loading a project that has a plain .txt file in it.

@Jagholin
Copy link

Can confirm the issue on 4.2.1. The editor also crashes often with a similar message, might be related
grafik

@dannyking
Copy link

Confirming the issue on 4.2.1 stable too. Happens when I save in an external editor (VSCode)

@miv391
Copy link
Contributor Author

miv391 commented Feb 14, 2024

I cannot reproduce this bug anymore with v4.3.dev2.official.

Edit: Oh yes, I can.

@akien-mga
Copy link
Member

Would be good to identify what fixed the bug in 4.3 so we could cherry-pick the fix to 4.2.
Alternatively we can go with #84907 as a workaround for 4.2.x.

I didn't manage to reproduce the bug in 4.2.1.stable myself to try to assess which dev snapshot first fixed the issue, but I'm not usually using VS Code as external editor so I might not have the appropriate configuration to trigger the bug.

@theraot
Copy link
Contributor

theraot commented Feb 14, 2024

Idk, what you are about... I have this issue in v4.3.dev2.official [3524346]:

image

And in v4.3.dev3.official [36e943b]

image

Could we be looking at two bugs with the same sympton?

This is how I reproduce: Have multiple scripts open in the Godot editor, open the project in Visual Studio Code (I have the extensions installed, addendum: both "C# Tools for Godot" and "godot-tools", I don't think that makes a difference), and I edit one script, one space added will do.

@miv391
Copy link
Contributor Author

miv391 commented Feb 15, 2024

I tested this again and yes, I can reproduce this after all. Now I used 4.3 dev3. I failed to reproduce the bug yesterday because I had set the Text Editor | Appearance | Highlight Type Safe Lines setting off. (Because then you do NOT get the "Index p_gutter" errors.)

@AlighaThor
Copy link

@miv391 Thanks! That workaround works good. This was driving me crazy... 😁

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

Successfully merging a pull request may close this issue.