fix(objects): properly destroy nodes

This commit is contained in:
Nova
2024-06-30 22:45:20 -04:00
parent 1e8d3a3d4c
commit b3fa529f77
6 changed files with 46 additions and 25 deletions

View File

@@ -22,11 +22,11 @@ pub struct InputMethod {
pub data: Mutex<InputDataType>,
pub datamap: Mutex<Datamap>,
pub capture_requests: Registry<InputHandler>,
pub captures: Registry<InputHandler>,
handler_aliases: AliasList,
handler_field_aliases: AliasList,
pub(super) handler_order: Mutex<Vec<Weak<InputHandler>>>,
pub capture_requests: Registry<InputHandler>,
pub captures: Registry<InputHandler>,
}
impl InputMethod {
pub fn add_to(
@@ -39,11 +39,11 @@ impl InputMethod {
data: Mutex::new(data),
datamap: Mutex::new(datamap),
capture_requests: Registry::new(),
captures: Registry::new(),
handler_aliases: AliasList::default(),
handler_field_aliases: AliasList::default(),
handler_order: Mutex::new(Vec::new()),
capture_requests: Registry::new(),
captures: Registry::new(),
};
<InputMethod as InputMethodRefAspect>::add_node_members(node);
<InputMethod as InputMethodAspect>::add_node_members(node);

View File

@@ -50,6 +50,13 @@ pub type Method = fn(Arc<Node>, Arc<Client>, Message, MethodResponseSender);
stardust_xr_server_codegen::codegen_node_protocol!();
pub struct OwnedNode(pub Arc<Node>);
impl Drop for OwnedNode {
fn drop(&mut self) {
self.0.destroy();
}
}
pub struct Node {
enabled: AtomicBool,
id: u64,
@@ -95,6 +102,14 @@ impl Node {
.scenegraph
.add_node(self))
}
pub fn add_to_scenegraph_owned(self) -> Result<OwnedNode> {
Ok(OwnedNode(
self.get_client()
.ok_or_else(|| eyre!("Internal: Unable to get client"))?
.scenegraph
.add_node(self),
))
}
pub fn enabled(&self) -> bool {
self.enabled.load(Ordering::Relaxed)
}