Compiler crashes when measuring schema.render #14

Open
opened 2025-10-31 09:16:12 +00:00 by rajayonin · 4 comments
Contributor

This makes the compiler crash:

#context measure(
  [
    #import "@preview/rivet:0.3.0": config, schema
    #schema.render(
      schema.load(
        (
          structures: (
            main: (
              bits: 16,
              ranges: (
                "3": (name: "MSIE"),
              ),
            ),
          ),
        ),
      ),
    )
  ]
)
thread 'main' panicked at crates/typst-layout/src/flow/distribute.rs:511:26:
assertion failed: size.is_finite()

I don't think it's CeTZ, because this works:

#context measure(
  [
    #import "@preview/cetz:0.4.2"
    #cetz.canvas({
      import cetz.draw: *
      circle((0, 0))
      line((0, 0), (2, 1))
    })
  ]
)

I've tested both Typst 0.13.1 and 0.14.0, and it gives the same result.

This makes the compiler crash: ```typst #context measure( [ #import "@preview/rivet:0.3.0": config, schema #schema.render( schema.load( ( structures: ( main: ( bits: 16, ranges: ( "3": (name: "MSIE"), ), ), ), ), ), ) ] ) ``` ``` thread 'main' panicked at crates/typst-layout/src/flow/distribute.rs:511:26: assertion failed: size.is_finite() ``` I don't think it's CeTZ, because this works: ```typst #context measure( [ #import "@preview/cetz:0.4.2" #cetz.canvas({ import cetz.draw: * circle((0, 0)) line((0, 0), (2, 1)) }) ] ) ``` I've tested both Typst 0.13.1 and 0.14.0, and it gives the same result.
Author
Contributor

There are also issues in general with scale, reflow, and figure captions:

If reflow is false, the size is correct but the caption not. If it's true, the reverse happens.
Using box gives the correct result.

#import "@preview/rivet:0.3.0": config, schema
#let sch = schema.render(
  schema.load(
    (
      structures: (
        main: (
          bits: 16,
          ranges: ("3": (name: "E")),
        ),
      ),
    ),
  ),
  config: config.config(
    margins: (0, 0, 0, 0),
    default-font-family: "DejaVu Sans Mono",
    italic-font-family: "Libertinus Serif",
  ),
)

#let width = 300pt


#show figure.caption: set align(left)

#figure(
  scale(x: width, y: auto, reflow: false, sch),
  caption: [`scale`, no reflow],
)

#figure(
  scale(x: width, y: auto, reflow: true, sch),
  caption: [`scale`, reflow],
)

#figure(
  box(width: width, sch),
  caption: [`box`],
)

#figure(
  scale(x: width, y: auto, reflow: true)[

    #import "@preview/cetz:0.4.2"
    #cetz.canvas({
      import cetz.draw: *
      circle((0, 0))
      line((0, 0), (2, 1))
    })
  ],
  caption: [CeTZ],
)

test.png

There are also issues in general with `scale`, `reflow`, and `figure` captions: If `reflow` is `false`, the size is correct but the caption not. If it's `true`, the reverse happens. Using `box` gives the correct result. ```typst #import "@preview/rivet:0.3.0": config, schema #let sch = schema.render( schema.load( ( structures: ( main: ( bits: 16, ranges: ("3": (name: "E")), ), ), ), ), config: config.config( margins: (0, 0, 0, 0), default-font-family: "DejaVu Sans Mono", italic-font-family: "Libertinus Serif", ), ) #let width = 300pt #show figure.caption: set align(left) #figure( scale(x: width, y: auto, reflow: false, sch), caption: [`scale`, no reflow], ) #figure( scale(x: width, y: auto, reflow: true, sch), caption: [`scale`, reflow], ) #figure( box(width: width, sch), caption: [`box`], ) #figure( scale(x: width, y: auto, reflow: true)[ #import "@preview/cetz:0.4.2" #cetz.canvas({ import cetz.draw: * circle((0, 0)) line((0, 0), (2, 1)) }) ], caption: [CeTZ], ) ``` ![test.png](/attachments/c5d14cd4-4952-4eb2-88dd-f38a29893bab)
143 KiB
HEL added the
bug
label 2025-10-31 22:24:24 +00:00
Author
Contributor

I've been looking and... why do you have this logic in the renderer?

src/renderer.typ Lines 535 to 563 in 3e74ad15ee
if config.full-page {
cnvs
} else {
layout(size => {
let m = measure(cnvs)
let w = m.width
let h = m.height
let base-w = if type(width) == ratio {
size.width * width
} else {
width
}
let r = if w == 0 {
0
} else {
base-w / w
}
let new-w = w * r
let new-h = h * r
r *= 100%
box(
width: new-w,
height: new-h,
scale(x: r, y: r, cnvs, reflow: true)
)
})
}

I've replaced that if-else with just cnvs, compiled the examples as PNG, and doing a diff shows that they are the same...

It doesn't solve the issue btw.

I've been looking and... why do you have this logic in the renderer? https://git.kb28.ch/HEL/rivet-typst/src/commit/3e74ad15ee68885b0ac729786418de9a3d6e36e7/src/renderer.typ#L535-L563 I've replaced that `if`-`else` with just `cnvs`, compiled the examples as PNG, and doing a `diff` shows that they are the same... It doesn't solve the issue btw.
Owner

The else case allows rescaling the diagram to a fixed width. I included it here so that users wouldn't have to implement it in their document if they needed a particular diagram to fit in the page without restructuring it

The `else` case allows rescaling the diagram to a fixed width. I included it here so that users wouldn't have to implement it in their document if they needed a particular diagram to fit in the page without restructuring it
Author
Contributor

Ok, I was confused because in config.config you can specify width (and height), but it gets overwritten by the one in schema.render.

I've seen the TODO -> remove comments... we should remove that.

Ok, I was confused because in `config.config` you can specify `width` (and `height`), but it gets overwritten by the one in `schema.render`. I've seen the `TODO -> remove` comments... we should remove that.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: HEL/rivet-typst#14
No description provided.