From f673b32567ff1d7b442a8bfe610ca81292e795ca Mon Sep 17 00:00:00 2001 From: Elena Torro Date: Tue, 21 Apr 2026 08:57:24 +0200 Subject: [PATCH] :bug: Fix image loading callback --- frontend/src/app/render_wasm/api.cljs | 20 ++++++++++++-------- render-wasm/src/wasm/fills/image.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index 897ea4aa55..96c3253c64 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -627,6 +627,7 @@ (if (empty? fills) (h/call wasm/internal-module "_clear_shape_fills") (let [fills (types.fills/coerce fills) + image-ids (types.fills/get-image-ids fills) offset (mem/alloc->offset-32 (types.fills/get-byte-size fills)) heap (mem/get-heap-u32)] @@ -648,7 +649,7 @@ (when (zero? cached-image?) (fetch-image shape-id id thumbnail?)))) - (types.fills/get-image-ids fills))))) + image-ids)))) (defn set-shape-strokes [shape-id strokes thumbnail?] @@ -675,7 +676,8 @@ (some? gradient) (do (types.fills.impl/write-gradient-fill offset dview opacity gradient) - (h/call wasm/internal-module "_add_shape_stroke_fill")) + (h/call wasm/internal-module "_add_shape_stroke_fill") + nil) (some? image) (let [image-id (get image :id) @@ -692,7 +694,8 @@ (some? color) (do (types.fills.impl/write-solid-fill offset dview opacity color) - (h/call wasm/internal-module "_add_shape_stroke_fill"))))) + (h/call wasm/internal-module "_add_shape_stroke_fill") + nil)))) strokes)) (defn set-shape-svg-attrs @@ -1302,16 +1305,17 @@ (when (or (seq pending-thumbnails) (seq pending-full)) (->> (rx/concat (->> (rx/from (vals pending-thumbnails)) - (rx/merge-map (fn [callback] (callback))) + (rx/merge-map + (fn [callback] + (if (fn? callback) (callback) (rx/empty)))) (rx/reduce conj [])) (->> (rx/from (vals pending-full)) - (rx/mapcat (fn [callback] (callback))) + (rx/mapcat + (fn [callback] + (if (fn? callback) (callback) (rx/empty)))) (rx/reduce conj []))) (rx/subs! (fn [_] - ;; Fonts are now loaded — recompute text - ;; layouts so Skia uses the real metrics - ;; instead of fallback-font estimates. (let [text-ids (into [] (comp (filter cfh/text-shape?) (map :id)) shapes)] (when (seq text-ids) (update-text-layouts text-ids))) diff --git a/render-wasm/src/wasm/fills/image.rs b/render-wasm/src/wasm/fills/image.rs index b122de4cc8..9200861f8a 100644 --- a/render-wasm/src/wasm/fills/image.rs +++ b/render-wasm/src/wasm/fills/image.rs @@ -1,11 +1,34 @@ use crate::error::{Error, Result}; use crate::mem; +use crate::shapes::Fill; +use crate::state::State; use crate::uuid::Uuid; use crate::with_state_mut; use crate::STATE; use crate::{shapes::ImageFill, utils::uuid_from_u32_quartet}; use macros::wasm_error; +fn touch_shapes_with_image(state: &mut State, image_id: Uuid) { + let ids: Vec = state + .shapes + .iter() + .filter(|shape| { + shape + .fills() + .any(|f| matches!(f, Fill::Image(i) if i.id() == image_id)) + || shape + .strokes + .iter() + .any(|s| matches!(&s.fill, Fill::Image(i) if i.id() == image_id)) + }) + .map(|shape| shape.id) + .collect(); + + for id in ids { + state.touch_shape(id); + } +} + const FLAG_KEEP_ASPECT_RATIO: u8 = 1 << 0; const IMAGE_IDS_SIZE: usize = 32; const IMAGE_HEADER_SIZE: usize = 36; // 32 bytes for IDs + 4 bytes for is_thumbnail flag @@ -90,7 +113,7 @@ pub extern "C" fn store_image() -> Result<()> { { eprintln!("{}", msg); } - state.touch_shape(ids.shape_id); + touch_shapes_with_image(state, ids.image_id); }); mem::free_bytes()?; @@ -167,7 +190,7 @@ pub extern "C" fn store_image_from_texture() -> Result<()> { // FIXME: Review if we should return a RecoverableError eprintln!("store_image_from_texture error: {}", msg); } - state.touch_shape(ids.shape_id); + touch_shapes_with_image(state, ids.image_id); }); mem::free_bytes()?;