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

Godot crashes when adding built-in scripts and defining variables before saving: ERROR: FATAL: Index p_index = 0 is out of bounds (size() = 0) #81149

Closed
mirage3d opened this issue Aug 30, 2023 · 3 comments · Fixed by #81156

Comments

@mirage3d
Copy link

mirage3d commented Aug 30, 2023

Godot version

v4.2.dev3.mono.official [013e8e3]

System information

Windows 11 - Godot 4.2.dev3.mono, Vulkan API 1.3.242 - Forward+ dedicated NVIDIA

Issue description

Adding a new built-in script to a node and while defining new variables in the script before saving the scene or the node/script, Godot will freeze momentarily after a couple of seconds then exit with the error:

ERROR: FATAL: Index p_index = 0 is out of bounds (size() = 0).
at: operator[] (./core/templates/list.h:521)

If the scene was saved before editing the script Godot does not crash.
If I edit the script anywhere other than the area for defining variables after the extends xxx and before the func _ready(), Godot does not crash whether the scene was saved or not.
Defining any kind of variable, whether @export, const, or var causes the crash.
If a normal (not built-in) script was added, Godot does not crash, whether the script was saved before editing or not.

Steps to reproduce

  1. Create a new scene.
  2. Add a new script to the root node, either from the "Attach new script" button in the scene hierarchy, or by choosing "New Script" from the drop-down in front of "Script" in the inspector under "Node" section.
  3. Check the "Built-in Script" option and click the "Create" button. Giving a name has no change on the crash behavior.
  4. Try adding a new variable definition after the extends line.
  5. Godot will crash while typing the variable definition line.

Minimal reproduction project

Unable to provide one, since Godot crashes because the scene and script crashes before they can be saved. The steps to reproduce the crash are already trivial and don't require much setting up.

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Aug 30, 2023

I can reproduce this bug by typing the following code after the extends line. And wait for a very short time it wll crash.

var s = 2
var s = "string"

But with only one line of var definition, I can not reproduce the bug.

For the situation I memtioned, I believe the error comes from here in script_text_editor.cpp:

for (List<ScriptLanguage::ScriptError>::Element *E = errors.front(); E; E = E->next()) {
    if (E->get().path.is_empty() || E->get().path != script->get_path()) {
        depended_errors[E->get().path].push_back(E->get());
        E->erase();
	 }
 }
String error_text = vformat(TTR("Error at (%d, %d):"), errors[0].line, errors[0].column) + " " + errors[0].message;

If all the error doesn't have a path, all elements in errors will be erased, so using errors[0] will crash. But anyway the path is empty doesn't necessary mean it's a depended error.

@mirage3d
Copy link
Author

mirage3d commented Aug 30, 2023

If I use an @export var ... line, only 1 line is sufficient to trigger the crash after a couple of seconds from the start of typing. Not sure how this might make things clearer, but that's what happens with me. One @export var ... line is sufficient to trigger a crash, unless the scene is saved.

@jsjtxietian
Copy link
Contributor

@mirage3d It's the same case. Only type @export var t will crash because this is not a valid statement and have syntax error. If have syntax error and have a unsaved scene, the editor will crash.

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.

3 participants