1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

GDScript: Initialize static variables with defaults in-editor

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.
This commit is contained in:
George Marques
2024-05-02 15:06:07 -03:00
parent 06d105e268
commit 22236380c0
2 changed files with 27 additions and 0 deletions

View File

@@ -169,6 +169,9 @@ private:
GDScriptFunction *static_initializer = nullptr;
Error _static_init();
#ifdef TOOLS_ENABLED
void _static_default_init(); // Initialize static variables with default values based on their types.
#endif
int subclass_count = 0;
RBSet<Object *> instances;