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

GDScript: Initialize static variables with defaults in-editor #91472

Conversation

vnen
Copy link
Member

@vnen vnen commented May 2, 2024

When the script is not marked as @tool the static constructor is not called and thus the variables contain null by default. But since some validated operations requires a valid value, this would cause a crash.

This commit solves this by initializing the static variables with a default value based on their types in the editor, when they are not marked as @tool, so if some @tool script access them, they will have a valid typed value, avoiding the crash.

Fix #87678
Fix #91358

When the script is not marked as `@tool` the static constructor is not
called and thus the variables contain `null` by default. But since some
validated operations requires a valid value, this would cause a crash.

This commit solves this by initializing the static variables with a
default value based on their types in the editor, when they are not
marked as `@tool`, so if some `@tool` script access them, they will have
a valid typed value, avoiding the crash.
@vnen vnen added this to the 4.3 milestone May 2, 2024
@vnen vnen requested a review from a team as a code owner May 2, 2024 18:12
Copy link
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@akien-mga akien-mga merged commit 4d43fe1 into godotengine:master May 2, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

Crash on indexing static null from GDScript Godot crashes when accessing static variables in @tool mode
3 participants