Skip to content

Crash on macOS Sonoma 14.5 when saving PNG/TIFF with ggsave (ragg/systemfonts/textshaping) #203

@Jsalas424

Description

@Jsalas424

Summary
On macOS Sonoma 14.5 (ARM64, R 4.5.1), ggsave() with PNG or TIFF devices crashes the R session when {ragg, textshaping, systemfonts} are involved. This occurs even for trivial ggplot2 plots. pdf output works fine.

The crash trace shows a segfault in FreeType’s COLRv1 handling (tt_face_get_paint_layers), called from systemfonts → harfbuzz → textshaping → ragg during string width measurement. After reinstalling {ragg, textshaping, systemfonts} from CRAN binaries and explicitly using ragg::agg_png or ragg::agg_tiff, the problem was resolved.

Minimal reprex

library(ggplot2)

# Crashes
ggsave("test.png", ggplot(mtcars, aes(mpg, wt)) + geom_point())

# Works after reinstall + explicit ragg device
ggsave("test.png",
       ggplot(mtcars, aes(mpg, wt)) + geom_point(),
       device = ragg::agg_png, width = 6, height = 4, units = "in", res = 300)

ggsave("test.tiff",
       ggplot(mtcars, aes(mpg, wt)) + geom_point(),
       device = ragg::agg_tiff, width = 6, height = 4, units = "in", res = 300,
       compression = "lzw")

Crash log (truncated)

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x000000000000004a

Thread 0 Crashed:
0   systemfonts.so      tt_face_get_paint_layers (ttcolr.c:1529)
1   libharfbuzz.0.dylib hb_ft_get_glyph_extents
2   textshaping.so      HarfBuzzShaper::fill_shape_info
3   ragg.so             textshaping::string_width
4   libR.dylib          GEStrWidth
5   grid.so             L_stringMetric
...

Environment

R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5

Packages:
- ragg 1.4.0
- systemfonts 1.2.3
- textshaping 1.0.1
- ggplot2 3.5.2

systemfonts::font_info("Helvetica") runs without issue.
ggsave(..., device = "pdf") always works.

Workarounds

Forcing Quartz device works:

ggsave("test.png", plot, device = function(...) grDevices::png(type = "quartz", ...))

Full fix: clean reinstall of {ragg, textshaping, systemfonts} from CRAN arm64 binaries. After that, ragg::agg_png and ragg::agg_tiff worked reliably.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions