Reproducible session crash with minimal (non)-working example supplied

I'm analyzing some image data -- basically:

  1. loading an svg file
  2. converting it to a bmp
  3. counting pixels
  4. overlaying a template
  5. recounting pixels
  6. saving result to a csv file

I have 56000+ svg files to do, but my script crashes within the first 10

library(tidyverse) 
library(magick)

data_output_file <- "pixel_data.csv"

template <- image_read("background_body.bmp") %>% 
  image_transparent(color="black", fuzz=50) 

system.time({
  for(i in 1:10) { # should be 56000+
    print(i)
    svg_filename <- paste("svg_files/", i, ".svg", sep="")
    bitmap <- image_read_svg(svg_filename) %>% 
      image_convert(format = "bmp") %>%
      image_convert(colorspace="gray") %>%
      image_threshold(type="black", threshold = "10%") %>%
      image_threshold(type="white", threshold = "90%") 
    overlay_image <- image_composite(bitmap, template, operator = "atop") %>%
      image_convert(colorspace="gray") %>%
      image_threshold(type="black", threshold = "10%") %>%
      image_threshold(type="white", threshold = "90%") 
    
    # The following two lines count pixels which are not entirely 'white'
    nPixels <- {{bitmap %>% image_data() %>% .[1,,]} != as.raw(255)} %>% sum()
    nPixels_outside <- {{overlay_image %>% image_data() %>% .[1,,]} != as.raw(255)} %>% sum()
    
    write.table(data.frame("id"= i, 
                           "nPix" = nPixels,
                           "nPixOut" = nPixels_outside), 
                data_output_file,
                sep=";",
                row.names = FALSE,
                col.names = ifelse(i==1, TRUE, FALSE),
                append=TRUE)
  }
}) # end system.time

I have tried attaching a gdb debugger to the process but that's not working at all (basically rstudio is responsive, but nothing happens in when executing code) ... I'm not familiar with gdb but did the following:

$sudo gdb
(gdb) attach 'pid-of-rsession'

(obviously with the actual pid number in the attach command)

A minimum workable example, including svg files is provided here: http://www.oneill.dk/test_proj_session_crash.zip