🐛 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

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

View file

@ -56,6 +56,12 @@ pub fn bytes() -> Vec<u8> {
.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 {
type BytesType;
fn from_bytes(bytes: Self::BytesType) -> Self;

View file

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