-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
impl AsObjectArg <T> makes T-object free #835
Comments
No, that shouldn't happen. My current plan is to make all APIs accept references, for a few reasons:
So this would mean removing the value |
Correct, |
Another error occurred today from |
Thanks! I think I see the problem -- it happens only for methods with default parameters: // impl RichTextLabel
pub fn add_image(&mut self, image: impl AsObjectArg<crate::classes::Texture2D>) {
self.add_image_ex(image).done()
}
pub fn add_image_ex(
&mut self,
image: impl AsObjectArg<crate::classes::Texture2D>, // <- local variable
) -> ExAddImage<'_> {
ExAddImage::new(self, image.as_object_arg())
} // <- drop `image`!
pub struct ExAddImage<'a> {
surround_object: &'a mut re_export::RichTextLabel,
image: ObjectArg<crate::classes::Texture2D>, // <- only stores pointer
...
}
impl< 'a > ExAddImage< 'a > {
fn new(surround_object: &'a mut re_export::RichTextLabel, image: ObjectArg<Texture2D>) -> Self {
Self { surround_object, image, ... }
}
} I.e. use-after-free error. For now, I'd recommend changing the calls to take borrows. As mentioned above, we'd likely enforce this soon, which would also address this issue. |
Hello, recently I've found suspicious behaviour in Godot runtime while using new pattern AsObjectArg in arguments. Godot prints error that object is null on such calls.
For example, I have a function that prints letter textures into RichTextLabel:
Godot logs errors in editor with a reference to this line: https://github.com/godotengine/godot/blob/15073afe3856abd2aa1622492fe50026c7d63dc1/scene/gui/rich_text_label.cpp#L3228
Similar issue was noticed in other functions PhysicsDirectSpaceState3D::like get_rest_info etc.
Here is two options to resolve the issue:
to.add_image(img.clone())
to.add_image(&img)
Is that behaviour expected?
The text was updated successfully, but these errors were encountered: