samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.67k stars 63 forks source link

Error: internal error in Neon module: called `Option::unwrap()` on a `None` value #149

Open stoneyallen opened 11 months ago

stoneyallen commented 11 months ago
const ctx = canvas.getContext('2d');
canvas.gpu = false;
ctx.setTransform(0, 0, 0, 0, 154, 271.60133333333334);
ctx.beginPath();
ctx.arc(0, 0, 2, 0, 6.283185307179586);
ctx.closePath();
ctx.fill();

After executing the above statement, an error will be reported. When setTransform is deleted, the error will disappear.

mpaperno commented 11 months ago

Did you mean to set the scaling terms to zero in your transform matrix?

I saw this recently also when trying to fill/stroke a path with an invalid transform.

The error comes from canvas/mod.rs @ 312 in draw_path() method due to the current transform not being invertable. Fix for error:

-      let inverse = self.state.matrix.invert().unwrap();
+      let inverse = self.state.matrix.invert().unwrap_or_default();

Though it still won't draw anything, just won't throw error 😉