🐛 Remove children correctly

This commit is contained in:
Elena Torro 2025-04-09 12:19:47 +02:00
parent 82cf474863
commit 953db56a0d
4 changed files with 13 additions and 14 deletions

View file

@ -198,9 +198,8 @@
(when-not (empty? entries) (when-not (empty? entries)
(let [id (first entries)] (let [id (first entries)]
(sr/heapu32-set-uuid id heap (mem/ptr8->ptr32 current-offset)) (sr/heapu32-set-uuid id heap (mem/ptr8->ptr32 current-offset))
(recur (rest entries) (+ current-offset CHILD-ENTRY-SIZE))))) (recur (rest entries) (+ current-offset CHILD-ENTRY-SIZE)))))))
(h/call wasm/internal-module "_set_children")))
(h/call wasm/internal-module "_set_children")))))
(defn- get-string-length [string] (+ (count string) 1)) (defn- get-string-length [string] (+ (count string) 1))

View file

@ -219,7 +219,8 @@ pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) {
#[no_mangle] #[no_mangle]
pub extern "C" fn set_children() { pub extern "C" fn set_children() {
let bytes = mem::bytes(); let bytes = mem::bytes_or_empty();
let entries: IndexSet<Uuid> = bytes let entries: IndexSet<Uuid> = bytes
.chunks(size_of::<<Uuid as SerializableResult>::BytesType>()) .chunks(size_of::<<Uuid as SerializableResult>::BytesType>())
.map(|data| Uuid::from_bytes(data.try_into().unwrap())) .map(|data| Uuid::from_bytes(data.try_into().unwrap()))
@ -237,13 +238,10 @@ pub extern "C" fn set_children() {
state.delete_shape(id); state.delete_shape(id);
} }
}); });
}
#[no_mangle] if !bytes.is_empty() {
pub extern "C" fn clear_shape_children() { mem::free_bytes();
with_current_shape!(state, |shape: &mut Shape| { }
shape.clear_children();
});
} }
#[no_mangle] #[no_mangle]

View file

@ -56,6 +56,12 @@ pub fn bytes() -> Vec<u8> {
.map_or_else(|| panic!("Buffer is not initialized"), |buffer| *buffer) .map_or_else(|| panic!("Buffer is not initialized"), |buffer| *buffer)
} }
pub fn bytes_or_empty() -> Vec<u8> {
let mut guard = BUFFERU8.lock().unwrap();
guard.take().map_or_else(|| Vec::new(), |buffer| *buffer)
}
pub trait SerializableResult { pub trait SerializableResult {
type BytesType; type BytesType;
fn from_bytes(bytes: Self::BytesType) -> Self; fn from_bytes(bytes: Self::BytesType) -> Self;

View file

@ -444,10 +444,6 @@ impl Shape {
(added, removed) (added, removed)
} }
pub fn clear_children(&mut self) {
self.children.clear();
}
pub fn fills(&self) -> std::slice::Iter<Fill> { pub fn fills(&self) -> std::slice::Iter<Fill> {
self.fills.iter() self.fills.iter()
} }