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:
parent
06d105e268
commit
22236380c0
2 changed files with 27 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue