-
-
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
free
can be used to cause a segfault entirely from rust
#348
Comments
Another related pattern that is harder to guard against: let child = Node::new_alloc();
let mut node = Node::new_alloc();
let node2 = node.share();
let node_deref = &mut *node;
node2.free();
// segfaults
node_deref.add_child(child.share());
child.free(); |
The most straightforward solution here would be to make But again, objects that dont inherit from I'm not sure if there's a good way to make a completely safe abstraction for this. |
Some conversation about this issue happening in this discord thread. |
#[derive(GodotClass)]
#[class(init, base = Node)]
pub struct Foo {
#[base]
base: Base<Node>,
node: Option<&'static mut Node>,
i: u64,
}
#[godot_api]
impl NodeVirtual for Foo {
fn ready(&mut self) {
if Engine::singleton().is_editor_hint() {
return;
}
let node = Node::new_alloc();
self.add_child(node.share());
self.node = Some(&mut *Box::leak(Box::new(node)));
}
fn process(&mut self, _delta: f64) {
let i = self.i;
if let Some(node) = &mut self.node {
match i {
0 => node.queue_free(),
1 => {
let child = Node::new_alloc();
node.add_child(child);
}
_ => (),
}
}
self.i += 1;
}
} |
Adding a node of class
Foo
will cause a segfault when the game runs.The text was updated successfully, but these errors were encountered: