-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Crash caused by Godot Editor allowing inserting null
into Array<Gd<T>>
#283
Comments
Regarding what the right thing to do is, I think exporting |
We should probably just make I'd prefer removing the null values though, unless that makes the editor act really weirdly. |
While there likely is no use in having null elements in an Array that cannot represent them, I think silently dropping those elements (and thus changing contents, and array length) might subtly subvert user expectations of receiving on the Rust end what they entered on the Godot end, and might lead to bugs (even if only semantic ones) where people are not aware of the non-null nature of e.g. Maybe we should automatically treat |
We would also need to test how GDScript handles |
I'm not sure if this would work for value types. But we should first see how godot treats this as Bromeon mentioned. |
Via the editor I pre-filled "foo" with 1, 2; and "bar" with a texture. Then I added another element in both arrays and did not change the added element (i.e. took the default the editor would insert). The output is as follows:
|
So the only case where our logic should fail here would be for inserting null objects into an |
@gg-yb so it looks like So I see two options:
(2) is more ergonomic, as it prevents unwrapping every time a user wants to access elements. We would need to define how we skip/remove the nulls though. |
it would be |
Is it possible for us to raise an error (one that does not crash the editor) when we get That would prevent pseudo-nullable Silently dropping elements on the rust side feels like something that may cause a lot of pain in the future, because that is not what people expect to happen when they add an element, especially if its the default element the editor inserts. I'd rather see an explicit |
Please do not drop |
But would this then not always cause an error whenever someone adds an element via editor, because it's initially null?
But what do people expect if the backing storage is declared as |
Ideally this would only occur once the user somehow shows intent to leave it that way (e.g. focus loss). I do not know when Godot actually tries to bring the editor contents into Rust, but if we cannot prevent the error from happening immediately, we should likely still show it.
We maybe should define So we should approach the topic in a way that is agnostic to even programming:
In this case: When I add an element to an array, it either is added, or an error is raised. This is my expectation as a dev, too. I call some method, it either does what it says it does, or it raises an error. And in a way, adding elements via the editor is like pushing into an array, complete with the same fear of "I can see it in the editor, why can't I see it from the code?" |
I feel like it's kind of an expectation that rust developers are familiar with nullability and how that's treated in rust. And if you're creating a gdext library then it's your responsibility to ensure that it works well when used as intended. So you shouldn't be using
I think that if the nulls were just dropped then they wouldn't show up in the editor on a reload. but we should definitely check out the ergonomics of doing it this way. as well as the other suggestions. My preference in order from most to least preferred is roughly:
I think option 1 would be best but it depends entirely on how well it works with the editor. If it creates a confusing user-experience it'd make it very unusable, and possibly more of a footgun than anything else. option 2 certainly works but I'd like for people to be able to export option 3 does work but it's a bit strange from a rust perspective to have an array with elements you can't really access. and it'd make there may be other alternatives but those are the main three i can think of. |
From what i can tell, this doesn't crash the editor now using godot 4.2.2 at least. Instead you get a panic when you try to access the null objects from the array. |
See also #282.
Apparently the editor allows
null
values in arrays in all cases. I did not check if this is an array-specific thing.gdext Version: 8990464 (master)
How to reproduce:
Export a
Array<Gd<Texture2D>>
property. In the editor panel, increase the array length, save the scene, then reopen the scene. The editor crashes with the following message:The project can no longer be opened, and changes to the Scene file have to be made by external means to restore the project.
The text was updated successfully, but these errors were encountered: