From c48d862d0f153c3920a824453855b5750c30efc3 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 25 Feb 2025 11:29:57 +0100 Subject: [PATCH] :bug: Fix problem with gradient in strokes --- frontend/src/app/render_wasm/api.cljs | 2 +- render-wasm/src/main.rs | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index 7244f1169..662838e08 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -347,7 +347,7 @@ offset (:offset stop)] [r g b a (* 100 offset)])) stops))))) - (h/call internal-module "_add_shape_stroke_stops" stops-ptr n-stops)) + (h/call internal-module "_add_shape_stroke_stops")) (some? image) (let [id (dm/get-prop image :id) diff --git a/render-wasm/src/main.rs b/render-wasm/src/main.rs index c6a8d0710..8a0799cce 100644 --- a/render-wasm/src/main.rs +++ b/render-wasm/src/main.rs @@ -546,20 +546,22 @@ pub extern "C" fn add_shape_stroke_radial_fill( } #[no_mangle] -pub extern "C" fn add_shape_stroke_stops(ptr: *mut shapes::RawStopData, n_stops: u32) { - let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); +pub extern "C" fn add_shape_stroke_stops() { + let bytes = mem::bytes(); + + let entries: Vec<_> = bytes + .chunks(size_of::()) + .map(|data| shapes::RawStopData::from_bytes(data.try_into().unwrap())) + .collect(); + + let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer"); if let Some(shape) = state.current_shape() { - let len = n_stops as usize; - - unsafe { - let buffer = Vec::::from_raw_parts(ptr, len, len); - shape - .add_stroke_gradient_stops(buffer) - .expect("could not add gradient stops"); - mem::free_bytes(); - } + shape + .add_stroke_gradient_stops(entries) + .expect("could not add gradient stops"); } + mem::free_bytes(); } // Extracts a string from the bytes slice until the next null byte (0) and returns the result as a `String`.