-
Notifications
You must be signed in to change notification settings - Fork 38
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
Registered properties of type VariantArray throw exception when declared as lateinit #569
Comments
lateinit variables works, see tests |
The lifecycle info can be found in the danger box here: https://godot-kotl.in/en/stable/user-guide/properties/#exporting-properties @MartinHaeusler was this the issue and this can be closed? |
@chippmann unfortunately no. Please consider the following class: @RegisterClass
class ArrayCrashTest: Node3D() {
@Export
@RegisterProperty
lateinit var testArray: VariantArray<Node3D>
} The steps to reproduce the issue are quite simple:
You will be faced with the following error immediately upon scene load: This only happens if all of the following conditions are met:
This happens for me with no autoloads and no other scripts in the scene. As you can see, my script never attempts to access the |
By the way, it would be super cool if this "Godot-JVM: An Exception has occurred!" would actually print the exception as well 😅 |
I have to investigate but knowing Godot's internal, I have my theory. If that's true, the crash will happen with the other container types as well. And there is not really any solution to allow lateinit like this to work. The rule would be to not use lateinit on containers in the first place and directly instantiate an empty one instead. |
@MartinHaeusler the exception which caused this, should actually be printed right before that. So the root cause should always be printed right before the line If that's not the case, this is a bug and I would be more than happy if it should occur, you file a separate issue so we can track it :-) |
The following property declaration works without any issues and behaves as expected:
However, the following property declaration:
... will throw an exception:
I can only assume that the
VariantArray
has something to do with it; it's the only difference I could spot. It doesn't make a difference if the property is ever used or not, the exception happens always when the scene loads.As a workaround, the following declaration works again without issues:
... but forces the programmer to deal with the
null
value at all call sites.The text was updated successfully, but these errors were encountered: