rspatial/terra

segfault when using rasterize with `cover = TRUE` and `by`

Closed this issue · 1 comments

When using cover = TRUE and passing the by arg to rasterize, segfault occurs.

library(terra)
#> terra 1.7.79
gdal(lib="all")
#>     gdal     proj     geos 
#>  "3.8.5"  "9.4.0" "3.12.1"
f <- system.file("ex/lux.shp", package = "terra")
v <- vect(f)
r <- rast(v, ncols = 75, nrows = 100)
z <- rasterize(v, r, cover = TRUE, by = "ID_2")

 *** caught segfault ***
address 0x0, cause 'memory not mapped'

Traceback:
 1: .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: 0x60000053f460>,     dll = list(name = "Rcpp", path = "/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/libs/Rcpp.so",         dynamicLookup = TRUE, handle = <pointer: 0x7ff91bb5b1c0>,         info = <pointer: 0x6000021307e0>), numParameters = -1L),     <pointer: 0x600003902400>, <pointer: 0x60000053ada0>, .pointer,     ...)
 2: x@ptr$split(f)
 3: methods::.hasSlot(x, "ptr")
 4: messages(x@ptr$split(f), "split")
 5: .local(x, f, ...)
 6: split(x, by)
 7: split(x, by)
 8: .local(x, y, ...)
 9: rasterize(v, r, cover = TRUE, by = "ID_2")
10: rasterize(v, r, cover = TRUE, by = "ID_2")

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

Created on 2024-06-19 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31)
#>  os       macOS Ventura 13.6.7
#>  system   x86_64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_AU.UTF-8
#>  ctype    en_AU.UTF-8
#>  tz       Australia/Melbourne
#>  date     2024-06-19
#>  pandoc   2.14.2 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.2   2023-12-11 [1] CRAN (R 4.3.0)
#>  codetools     0.2-19  2023-02-01 [1] CRAN (R 4.3.2)
#>  digest        0.6.35  2024-03-11 [1] CRAN (R 4.3.2)
#>  evaluate      0.23    2023-11-01 [1] CRAN (R 4.3.0)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.3.3)
#>  fs            1.6.4   2024-04-25 [1] CRAN (R 4.3.2)
#>  glue          1.7.0   2024-01-09 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.3.2)
#>  knitr         1.45    2023-10-30 [1] CRAN (R 4.3.0)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.0)
#>  purrr         1.0.2   2023-08-10 [1] CRAN (R 4.3.0)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo          1.26.0  2024-01-24 [1] CRAN (R 4.3.2)
#>  R.utils       2.12.3  2023-11-18 [1] CRAN (R 4.3.0)
#>  Rcpp          1.0.12  2024-01-09 [1] CRAN (R 4.3.0)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang         1.1.3   2024-01-10 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.26    2024-03-05 [1] CRAN (R 4.3.2)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.0)
#>  styler        1.10.2  2023-08-29 [1] CRAN (R 4.3.0)
#>  terra       * 1.7-79  2024-05-27 [1] Github (rspatial/terra@fe50dec)
#>  vctrs         0.6.5   2023-12-01 [1] RSPM (R 4.3.0)
#>  withr         3.0.0   2024-01-16 [1] CRAN (R 4.3.0)
#>  xfun          0.44    2024-05-15 [1] CRAN (R 4.3.3)
#>  yaml          2.3.8   2023-12-11 [1] CRAN (R 4.3.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

As at 80120c3 all seems fine and I can no longer reproduce this.