DjDeveloperr / skia_canvas

Fast HTML Canvas API implementation for Deno using Google Skia
https://jsr.io/@gfx/canvas
Apache License 2.0
132 stars 9 forks source link

Cannot read private member #ptr from an object whose class did not declare it #59

Closed backspaces closed 1 year ago

backspaces commented 1 year ago

I get this error below when running this simple method deep within a fairly complex project.

export function setIdentity(ctx) {
    ctx.save() 
    ctx.resetTransform() 
}
master: tests/denomodel.js 
cwd /Users/owen/Dropbox/src/agentscript
cwd /Users/owen/Dropbox/src/models
file:///Users/owen/Dropbox/src/agentscript/models/AvalancheModel.js
setIdentity ctx CanvasRenderingContext2D { canvas: Canvas {} }
error: Uncaught (in promise) TypeError: Cannot read private member #ptr from an object whose class did not declare it
    sk_context_save(this.#ptr);
                         ^
    at CanvasRenderingContext2D.save (https://deno.land/x/skia_canvas@0.5.2/src/context2d.ts:1117:26)
    at setIdentity (file:///Users/owen/Dropbox/src/agentscript/src/domUtils.js:201:9)
    at fillCtxWithImage (file:///Users/owen/Dropbox/src/agentscript/src/domUtils.js:297:5)
    at Module.imageToCtx (file:///Users/owen/Dropbox/src/agentscript/src/domUtils.js:289:5)
    at new RGBDataSet (file:///Users/owen/Dropbox/src/agentscript/src/RGBDataSet.js:60:26)
    at Object.tileDataSet (file:///Users/owen/Dropbox/src/agentscript/src/TileData.js:45:16)
    at Object.zxyToDataSet (file:///Users/owen/Dropbox/src/agentscript/src/TileData.js:36:30)
    at eventLoopTick (ext:core/01_core.js:182:11)
    at async AvalancheModel.startup (file:///Users/owen/Dropbox/src/agentscript/models/AvalancheModel.js:24:22)
    at async Module.runModel (file:///Users/owen/Dropbox/src/agentscript/src/jsUtils.js:895:5)

The CanvasRenderingContext2D is made as shown in the docs:

const canvas = createCanvas(300, 300);
const ctx = canvas.getContext("2d");

I don't think this error is a javascript error but buried deep within skiaCanvas.

Can you think how this could happen? What the error code suggests?

DjDeveloperr commented 1 year ago

#ptr is private property. JS is strict about its access, there is probably some complex process going on that breaks when canvas uses private properties. However, for proper spec conformance, I will change it to use unique symbols for private properties which are less strict. I'll do this sometime this weekend.

backspaces commented 1 year ago

Very nice, thanks. I'll check to see that it works fine in the browser.

backspaces commented 1 year ago

OK, checked browser and all 24 models work fine in browser. Goal is to get all 24 running in deno. CountiesModel & AvalancheModel still fail in deno.

backspaces commented 1 year ago

Er..running in deno === running in deno main and in worker. I think the worker freeze is handled in the prior issue but not yet tested against the 24 models.

DjDeveloperr commented 1 year ago

I got sidetracked by other projects last weekend, I’ll get to this after work today!

Private property error can be quite easily fixed, but I didn’t quite understand the last message. Does it mean this same error shows up in workers too? If that, then it’s expected. Wonder what is going on with the code to violate private property access.

backspaces commented 1 year ago

The last message was to summarize my overall deno goals, not specifically related to this issue. No worries! And thanks for getting on this so quickly.

DjDeveloperr commented 1 year ago

Should be fixed in 084f972 - I'll make a new release in some time

Update: While it worked fine on macOS locally for me, macOS CI seems to have failed. I’ll check this tomorrow after work (before if possible) again, as its time for me to sleep now

DjDeveloperr commented 1 year ago

Seems like I forgot to update version in 0.5.3 metadata which causes old binary to be downloaded..

Update: Published 0.5.4 which should do the job

backspaces commented 1 year ago

YeY .. all 24 models work fine in deno main. I'll test workers shortly. Nice job DjD.

DjDeveloperr commented 1 year ago

Should I close this issue, now that it is resolved?

backspaces commented 1 year ago

Yup, we'll close this now. Thanks for your help!