GlobalFonts.register
uses reference to passed-in Buffer which can be invalidated
#1006
Labels
bug
Something isn't working
The register function takes a Buffer of the font data, but it makes the registered font reference the memory owned by the Buffer instead of making a copy of the data. See:
canvas/skia-c/skia_c.cpp
Line 1712 in e609b20
This is fine sometimes, but it doesn't work if the buffer will get overwritten or if it gets garbage-collected. oven-sh/bun#17620 is an example of unexpected behavior caused by this issue.
Here is a script to demonstrate this problem:
When run normally,
out.png
has the text "hello world" visible:When run with the environment variable
OVERWRITE=1
, the image is blank because the font data isn't valid anymore:I believe either
GlobalFonts.register
should make a copy of the Buffer data to ensure that it can always access the font data, or it should be clearly documented that the user needs to pass in a Buffer that will never be overwritten nor garbage-collected.The text was updated successfully, but these errors were encountered: