Since 0.19.1, exporting text models to SVG can throw
Cannot read properties of undefined (reading 'length'), depending on the
font and size. We hit this with models.Text using Allerta Stencil — the
5 glyph at font sizes around 1.25–2.25 crashes the export.
The winding check added in #643 calls path.toKeyPoints on every chain link,
and that function returns undefined (instead of IPoint[]) for degenerate
bezier seeds. Glyph outlines commonly contain near-zero-length curve
segments, so text is a reliable way to trigger it. 0.19.0 and earlier don't
hit this code path during export.
Repro without fonts, using a seed captured from the Allerta 5:
const makerjs = require('makerjs') // 0.19.2
const seed = {
type: 'bezier-seed',
origin: [0.271728515625, 0.642333984375],
controls: [[0.27099609375, 0.6357421875]],
end: [0.27099609375, 0.63427734375]
}
console.log(makerjs.path.toKeyPoints(seed)) // undefined
makerjs.exporter.toSVG({
paths: {
seed,
line1: new makerjs.paths.Line(seed.end, [0, 0]),
line2: new makerjs.paths.Line([0, 0], seed.origin)
}
})
// TypeError: Cannot read properties of undefined (reading 'length')
// at chain.toKeyPoints / isChainClockwise / chainToSVGPathData
The cause is in path.toKeyPoints: the BezierSeed branch only assigns
curveKeyPoints when findChains finds exactly one chain or one loose path.
This seed's arc approximation produces two tiny chains, so nothing is
assigned and undefined comes back. chain.toKeyPoints then reads
.length on it.
return curveKeyPoints || [] would fix it — a segment this small doesn't
meaningfully affect the winding result, and the chain's other links still
determine direction. Happy to submit a PR with a test if that sounds right.
We're currently working around this by monkey-patching path.toKeyPoints
to return [] instead of undefined.
Since 0.19.1, exporting text models to SVG can throw
Cannot read properties of undefined (reading 'length'), depending on thefont and size. We hit this with
models.Textusing Allerta Stencil — the5glyph at font sizes around 1.25–2.25 crashes the export.The winding check added in #643 calls
path.toKeyPointson every chain link,and that function returns
undefined(instead ofIPoint[]) for degeneratebezier seeds. Glyph outlines commonly contain near-zero-length curve
segments, so text is a reliable way to trigger it. 0.19.0 and earlier don't
hit this code path during export.
Repro without fonts, using a seed captured from the Allerta
5:The cause is in
path.toKeyPoints: the BezierSeed branch only assignscurveKeyPointswhenfindChainsfinds exactly one chain or one loose path.This seed's arc approximation produces two tiny chains, so nothing is
assigned and
undefinedcomes back.chain.toKeyPointsthen reads.lengthon it.return curveKeyPoints || []would fix it — a segment this small doesn'tmeaningfully affect the winding result, and the chain's other links still
determine direction. Happy to submit a PR with a test if that sounds right.
We're currently working around this by monkey-patching
path.toKeyPointsto return
[]instead ofundefined.