Myriad-Dreamin / typst.ts

Run Typst in JavaScriptWorld.
https://myriad-dreamin.github.io/typst.ts
Apache License 2.0
294 stars 14 forks source link

Cannot render vector artifact: `recursive use of an object detected which would lead to unsafe aliasing in rust` #515

Open OverflowCat opened 2 months ago

OverflowCat commented 2 months ago

Describe the bug When rendering artifact in SVG mode, the renderer throws Error: recursive use of an object detected which would lead to unsafe aliasing in rust.

To Reproduce

Compile a hello world using CLI (v0.4.1)[https://github.com/Myriad-Dreamin/typst.ts/releases/tag/v0.4.1].

Render the main.artifact.sir.in artifact using the node.js-next example, or $typst.svg({ vectorData }) in all-in-one.

node ./dist/esm/main.js
panicked at crates\reflexo\src\vector\stream.rs:38:69:
called `Result::unwrap()` on an `Err` value: CheckBytesError(StructCheckError { field_name: "metadata", inner: ContextError(ArchiveError(SubtreePointerOutOfBounds { ptr: 0x132268, subtree_range: 0x130270..0x132260 })) })

Stack:

Error
    at file:///████████/typst.ts/templates/node.js-next/node_modules/.pnpm/@myriaddreamin+typst-ts-renderer@0.5.0-rc3/node_modules/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer.mjs:1567:21
    at logError (file:///████████/typst.ts/templates/node.js-next/node_modules/.pnpm/@myriaddreamin+typst-ts-renderer@0.5.0-rc3/node_modules/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer.mjs:225:18)
    at imports.wbg.__wbg_new_abda76e883ba8a5f (file:///████████/typst.ts/templates/node.js-next/node_modules/.pnpm/@myriaddreamin+typst-ts-renderer@0.5.0-rc3/node_modules/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer.mjs:1566:66)
    at wasm://wasm/0043af92:wasm-function[1835]:0xedbc5
    at wasm://wasm/0043af92:wasm-function[865]:0xc2c71
    at wasm://wasm/0043af92:wasm-function[1396]:0xe5aff
    at wasm://wasm/0043af92:wasm-function[1202]:0xdb203
    at wasm://wasm/0043af92:wasm-function[313]:0x7251e
    at wasm://wasm/0043af92:wasm-function[302]:0x6dbd2
    at wasm://wasm/0043af92:wasm-function[547]:0xa77d5

file:///████████/typst.ts/templates/node.js-next/node_modules/.pnpm/@myriaddreamin+typst-ts-renderer@0.5.0-rc3/node_modules/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer.mjs:1973
        throw new Error(getStringFromWasm0(arg0, arg1));
              ^

Error: recursive use of an object detected which would lead to unsafe aliasing in rust
    at imports.wbg.__wbindgen_throw (file:///████████/typst.ts/templates/node.js-next/node_modules/.pnpm/@myriaddreamin+typst-ts-renderer@0.5.0-rc3/node_modules/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer.mjs:1973:15)
    at wasm://wasm/0043af92:wasm-function[1817]:0xebda2
    at wasm://wasm/0043af92:wasm-function[1816]:0xebd97
    at wasm://wasm/0043af92:wasm-function[715]:0xb95ce
    at RenderSession.free (file:///████████/typst.ts/templates/node.js-next/node_modules/.pnpm/@myriaddreamin+typst-ts-renderer@0.5.0-rc3/node_modules/@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer.mjs:784:14)
    at TypstRendererDriver.runWithSession (file:///████████/typst.ts/templates/node.js-next/node_modules/.pnpm/@myriaddreamin+typst.ts@0.5.0-rc3_@myriaddreamin+typst-ts-renderer@0.5.0-rc3/node_modules/@myriaddreamin/typst.ts/dist/esm/renderer.mjs:567:21)
    at async main (file:///████████/typst.ts/templates/node.js-next/dist/esm/main.js:15:17)

Desktop (please complete the following information):

Package/Software version (using command typst-ts-cli --VV full and paste down the output):

typst-ts-cli version 0.4.1
features: embedded_cjk_fonts embedded_emoji_fonts embedded_fonts gen_manual pdf serde_json serde_rmp svg text

program-ver: v0.4.1-dirty
program-rev: 58f88e9842905d70c6822e8fd2db8b3e9a59be27
program-build: aarch64-apple-darwin with opt_level(3) at 2023-12-05T03:06:40.180010000Z

rustc-ver: 1.74.0
rustc-rev: 79e9716c980570bfd1f666e3b16ac583f0168962
rustc-build: x86_64-apple-darwin-stable with LLVM 17.0
Myriad-Dreamin commented 2 months ago

The typst-ts-cli must have exact same version as the version which you specified in the in typst.ts, otherwise you will get a CheckBytesError error. For example, if the typst.ts is installed as 0.5.0-rc2, the typst-ts-cli must be also 0.5.0-rc2.

OverflowCat commented 2 months ago

Thanks for clarifying! It would be even better if this requirement was prominently noted in the documentation or if there was a version check for the artifact.

Myriad-Dreamin commented 2 months ago

I was considering adding a notes, but I don't know where to add it, as you may be missing it for some reason and ask again. From a short reconsideration, I would like to add it to the "Troubleshooting" page.