samizdatco / skia-canvas

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

width-variable is reserved for skia-canvas, is it a bug or a feature? #61

Closed ProgrammingLife closed 2 years ago

ProgrammingLife commented 2 years ago

Tried to change this working code:

const canvas = new Canvas( 1920, 1080 )
const ctx = canvas.getContext( "2d" )
const { width, height } = canvas

to this:

const canvas = new Canvas( 1920, 1080 )
const ctx = canvas.getContext( "2d" )
const { canvas_width, height } = canvas // renamed here

And I got broken code with the message:

» tsc && node dist/test.js
/home/user/nodejs/node_modules/skia-canvas/lib/index.js:54
    return this.native[fn](this[ø], ...args)
                          ^
TypeError: x must be a number
    at CanvasRenderingContext2D.ƒ (/home/user/nodejs/node_modules/skia-canvas/lib/index.js:54:27)
    at CanvasRenderingContext2D.fillText (/home/user/nodejs/node_modules/skia-canvas/lib/index.js:410:10)
    at start (/home/user/path/test.js:56:13)
Node.js v17.0.1

If I rename it back - all work fine again. Is it a bug or a feature?

samizdatco commented 2 years ago

I think you'll find that the canvas_width variable you created has the value undefined since the canvas object doesn't have an attribute with that name. Here's how you rename values when using destructuring assignment.

You're getting an error from fillText() because it expected a number rather than undefined.

ProgrammingLife commented 2 years ago

@samizdatco, omg shame on me. I need more rest. 😀 Thank you for the reply!