r-lib / svglite

A lightweight svg graphics device for R
https://svglite.r-lib.org
180 stars 39 forks source link

Segfault in svglite 1.2.0 #80

Closed jeroen closed 8 years ago

jeroen commented 8 years ago

An example in the rsvg package is segfaulting after the svglite update (or perhaps one of it's dependencies). The problem is in svglite; I can reproduce the problem without rsvg as well (on the latest Fedora stable).

The crash appears somewhat randomly which suggests a memory corruption caused earlier on. A reproducible example without rsvg:

options(example.ask=FALSE)
tmp <- tempfile()

# Create svg with basic SG
svg(tmp, width = 10, height = 7)
ggplot2::qplot(mpg, wt, data = mtcars, colour = factor(cyl))
dev.off()

# start svglite devices causes crash
svglite::svglite(tmp, width = 10, height = 7)
## R: fccache.c:545: FcCacheFini: Assertion `fcCacheChains[i] == NULL' failed.
## Aborted

This problem does not appear on mac and windows I think.

lionel- commented 8 years ago

judging from the error message, that would be gdtools. I'll look into it.

This problem does not appear on mac and windows I think.

I ran revdep_check() on a mac :/

jeroen commented 8 years ago

On mac you can test using docker for mac:

docker pull fedora:latest
docker run -i -t fedora:latest /bin/bash

And then install R and svglite, etc.

lionel- commented 8 years ago

Could you give the result of gdtools::version_fontconfig() please.

lionel- commented 8 years ago

Seems to be the same issue: https://groups.google.com/forum/#!topic/shiny-discuss/5kuGWnEb_LE

timelyportfolio commented 8 years ago

I just checked on Windows 10, and no error. It did hang for a while but eventually worked.

lionel- commented 8 years ago

The hang is fontconfig building a cache of the system fonts and should only happen once.

timelyportfolio commented 8 years ago

second try was quick as you suggest. Thanks!

lionel- commented 8 years ago

The Cairo svg device initialises fontconfig only once per session:

https://github.com/wch/r-source/blob/7a39bb9cf2d90571209d82f826976d53faf10bf8/src/library/grDevices/src/cairo/cairoFns.c#L678

and doesn't finalise it. Maybe it does not clean up other related resources correctly and this triggers the crash when we try to finalise fontconfig in gdtools. Quick solution: not finalising fontconfig in gdtools to be on the safe side.