mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
🐛 Fix wasm crash in set_shape_fills (wasm) when fill list is empty
This commit is contained in:
parent
ab0219876e
commit
a30ab17605
1 changed files with 26 additions and 25 deletions
|
@ -8,7 +8,7 @@
|
||||||
"A WASM based render API"
|
"A WASM based render API"
|
||||||
(:require
|
(:require
|
||||||
["react-dom/server" :as rds]
|
["react-dom/server" :as rds]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d :refer [not-empty?]]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.matrix :as gmt]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
@ -240,36 +240,37 @@
|
||||||
|
|
||||||
(defn set-shape-fills
|
(defn set-shape-fills
|
||||||
[fills]
|
[fills]
|
||||||
(let [fills (take types.fill/MAX-FILLS fills)
|
(when (not-empty? fills)
|
||||||
image-fills (filter :fill-image fills)
|
(let [fills (take types.fill/MAX-FILLS fills)
|
||||||
offset (mem/alloc-bytes (* (count fills) sr-fills/FILL-BYTE-SIZE))
|
image-fills (filter :fill-image fills)
|
||||||
heap (mem/get-heap-u8)
|
offset (mem/alloc-bytes (* (count fills) sr-fills/FILL-BYTE-SIZE))
|
||||||
dview (js/DataView. (.-buffer heap))]
|
heap (mem/get-heap-u8)
|
||||||
|
dview (js/DataView. (.-buffer heap))]
|
||||||
|
|
||||||
;; write fill data to heap
|
;; write fill data to heap
|
||||||
(loop [fills (seq fills)
|
(loop [fills (seq fills)
|
||||||
current-offset 0]
|
current-offset 0]
|
||||||
(when-not (empty? fills)
|
(when-not (empty? fills)
|
||||||
(let [fill (first fills)]
|
(let [fill (first fills)]
|
||||||
(sr-fills/write-fill! offset dview fill)
|
(sr-fills/write-fill! offset dview fill)
|
||||||
(recur (rest fills) (+ current-offset sr-fills/FILL-BYTE-SIZE)))))
|
(recur (rest fills) (+ current-offset sr-fills/FILL-BYTE-SIZE)))))
|
||||||
|
|
||||||
;; send fills to wasm
|
;; send fills to wasm
|
||||||
(h/call wasm/internal-module "_set_shape_fills")
|
(h/call wasm/internal-module "_set_shape_fills")
|
||||||
|
|
||||||
;; load images for image fills if not cached
|
;; load images for image fills if not cached
|
||||||
(keep (fn [fill]
|
(keep (fn [fill]
|
||||||
(let [image (:fill-image fill)
|
(let [image (:fill-image fill)
|
||||||
id (dm/get-prop image :id)
|
id (dm/get-prop image :id)
|
||||||
buffer (uuid/get-u32 id)
|
buffer (uuid/get-u32 id)
|
||||||
cached-image? (h/call wasm/internal-module "_is_image_cached"
|
cached-image? (h/call wasm/internal-module "_is_image_cached"
|
||||||
(aget buffer 0)
|
(aget buffer 0)
|
||||||
(aget buffer 1)
|
(aget buffer 1)
|
||||||
(aget buffer 2)
|
(aget buffer 2)
|
||||||
(aget buffer 3))]
|
(aget buffer 3))]
|
||||||
(when (zero? cached-image?)
|
(when (zero? cached-image?)
|
||||||
(store-image id))))
|
(store-image id))))
|
||||||
image-fills)))
|
image-fills))))
|
||||||
|
|
||||||
(defn set-shape-strokes
|
(defn set-shape-strokes
|
||||||
[strokes]
|
[strokes]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue