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 accessing static variables in @tool mode #87678

Closed
tokengamedev opened this issue Jan 28, 2024 · 3 comments · Fixed by #91472
Closed

Godot crashes when accessing static variables in @tool mode #87678

tokengamedev opened this issue Jan 28, 2024 · 3 comments · Fixed by #91472

Comments

@tokengamedev
Copy link

tokengamedev commented Jan 28, 2024

Tested versions

Reproducible in

  • 4.2.2 RC1
  • 4.2.1 Stable

System information

Windows 11

Issue description

When you try to access static variables in @tool mode. The Godot editor crashes without any logs or messages

Steps to reproduce

Create two files as given below:

# Scene file
@tool
extends Node2D
@export var setup: bool = false:
	set(value):
		setup = value
		print(Fluid.KIND[12]) # Cause of crash as KIND is null


# Fluid File (Note: No @tool annotation)
class_name Fluid

static var KIND := {12: "River" }

When you toggle the setup Godot will crash as it will try to print static variable.
It should print error message like Invalid get index '12' (on base: 'Nil'). rather than crashing

If you add @tool annotation it does not crash and gives the right values

Minimal reproduction project (MRP)

If required will be provided

@IceflowRE
Copy link
Contributor

Related #81250

@LeoDog896
Copy link

A reply on that related issue was mentioned by @dalexeev:

If you add @tool to the preloaded script it will work. We have some inconsistency here: in some cases @tool is optional to run dependency code, in other cases it is required (usually Nodes, but in some other cases too, example). I'm not sure if this is a bug as it prevents non-@tool code from being auto-executed.

While crashing is still (absolutely) a bug, should GDScript instead throw an error about not being able to depend on static variables from other non-tool scripts in a tool script?

@IceflowRE
Copy link
Contributor

A reply on that related issue was mentioned by @dalexeev:

If you add @tool to the preloaded script it will work. We have some inconsistency here: in some cases @tool is optional to run dependency code, in other cases it is required (usually Nodes, but in some other cases too, example). I'm not sure if this is a bug as it prevents non-@tool code from being auto-executed.

While crashing is still (absolutely) a bug, should GDScript instead throw an error about not being able to depend on static variables from other non-tool scripts in a tool script?

The best would be to fix #81250.

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.

5 participants