Skip to content

Commit d8e6fe3

Browse files
committed
Close graphics device before creating images
1 parent 4e5f9c5 commit d8e6fe3

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

R/gifski.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ save_gif <- function(expr, gif_file = 'animation.gif', width = 800, height = 600
7070
on.exit(unlink(imgdir, recursive = TRUE))
7171
filename <- file.path(imgdir, "tmpimg_%05d.png")
7272
grDevices::png(filename, width = width, height = height, ...)
73-
on.exit(grDevices::dev.off(), add = TRUE, after = FALSE)
7473
graphics::par(ask = FALSE)
75-
eval(expr)
74+
tryCatch(eval(expr), finally = dev.off())
7675
images <- list.files(imgdir, pattern = 'tmpimg_\\d{5}.png', full.names = TRUE)
7776
gifski(images, gif_file = gif_file, width = width, height = height, delay = delay, loop = loop, progress = progress)
7877
}

0 commit comments

Comments
 (0)