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

Certain autocomplete of literals causes editor crash #96239

Closed
AinaVT opened this issue Aug 28, 2024 · 2 comments · Fixed by #96243
Closed

Certain autocomplete of literals causes editor crash #96239

AinaVT opened this issue Aug 28, 2024 · 2 comments · Fixed by #96243

Comments

@AinaVT
Copy link
Contributor

AinaVT commented Aug 28, 2024

Tested versions

  • Reproducible in: 4.4.dev1
  • Not reproducible in: 4.3.stable and earlier.

System information

Godot v4.4.dev1 - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 (NVIDIA; 31.0.15.4617) - AMD Ryzen 5 3600 6-Core Processor (12 Threads)

Issue description

Certain autocomplete requests of literals causes a crash in the editor. This mainly occurs when trying to insert literal values as parameters to function calls for Autoload scripts, Static functions, and regular functions in specific circumstances.

Examples:

Assuming the Autoloaded script:

extends Node


func test_call(num):
	print(num)

and the call from another node:

extends Node3D


func _ready():
	AutoloadScript.test_call(10) # Crashes the editor while typing the number literal

The editor crashes when attempting to make a completion request while typing the literal value "10".

A similar problem happens with static functions:

class_name StaticScript
extends Object


static func test_call(num) :
	print(num)
extends Node3D


func _ready():
	StaticScript.test_call(10) # Crashes the editor while typing the number literal

This also happens when trying to type literal as parameters for function calls of scripts instantiated in the same scope as the call:

class_name RegularScript
extends RefCounted


func test_call(num: int):
	print(num)
extends Node3D

var regular_member = RegularScript.new()

func _ready():
	regular_member.test_call(10) # Does NOT crash the editor
	
	var regular_scoped = RegularScript.new()
	regular_scoped.test_call(10) # Crashes the editor thile typing the number literal

The examples above are using int literals, but it seems to be triggered by any kind of literal:

  • Any int and float literal after giving enough of a brief pause while typing
  • Any string, seems to immediatelly crash when opening double quotes
  • Any keyword literal, like null, true, or false, which seems to trigger as soon as you finish typing the word

Steps to reproduce

Autoload scripts

  • Create a script with a function and set it up as an Autoload
  • In another script, try to call that function while attempting to type a literal value as a parameter
  • Editor should crash

Static functions

  • Create a script with a class_name and a static function
  • In another script, try to call that static function while attempting to type a literal value as a parameter
  • Editor should crash

Regular functions

  • Create a script with a function
  • In another script, instantiate and call the function in the same scope while attempting to type a literal value as a parameter
  • Editor should crash

Minimal reproduction project (MRP)

crash-reproduction.zip

@AinaVT
Copy link
Contributor Author

AinaVT commented Aug 28, 2024

Out of curiosity, I attempted to clone the godot repository and tried to debug to see if I could see what was triggering this issue, since the editor itself wasn't giving any logs.
It seems to be caused by the method GDScriptParser::override_completion_context not setting the parser to the CompletionContext, which ends up causing an access violation later.
Adding this line to that method before setting the completion_context variable seems to stop the crash:

context.parser = this;

But i'm not sure if this will cause any other issues, as i'm not familiar at all with godot's codebase.

@HolonProduction
Copy link
Member

HolonProduction commented Aug 28, 2024

You are right it should be set there 👍
I guess I missed that since context.parser was introduced after I made the override_completion_context PR

Feel free to make a PR if you want to, otherwise I'll fix it together with some other regression from #94082

@github-project-automation github-project-automation bot moved this to For team assessment in GDScript Issue Triage Aug 28, 2024
@dalexeev dalexeev added this to the 4.4 milestone Aug 28, 2024
@dalexeev dalexeev moved this from For team assessment to Up for grabs in GDScript Issue Triage Aug 28, 2024
@dalexeev dalexeev moved this from Up for grabs to Fix pending review in GDScript Issue Triage Aug 28, 2024
@github-project-automation github-project-automation bot moved this from Fix pending review to Done in GDScript Issue Triage Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants