Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C stack usage errors during gdalwarp with "-multi" option enabled #1994

Closed
fdetsch opened this issue Sep 6, 2022 · 2 comments
Closed

C stack usage errors during gdalwarp with "-multi" option enabled #1994

fdetsch opened this issue Sep 6, 2022 · 2 comments

Comments

@fdetsch
Copy link
Contributor

fdetsch commented Sep 6, 2022

When running the following code,

src = system.file(
  "tif/geomatrix.tif"
  , package = "sf"
)

dst = file.path(
  tempdir()
  , "geomatrix.tif"
)

n = 1L

while (n <= 5L) {
  sf::gdal_utils(
    "warp"
    , source = src
    , destination = dst
    , options = c(
      "-overwrite"
      , "-multi"
    )
    , quiet = FALSE
  )
  
  n = n + 1L
}

I encounter C stack usage errors (and a concomitant RStudio freeze) like this:

Creating output file that is 25P x 25L.
0...10...20...30...40...50...60...70...80...90Error: C stack usage  947109039916 is too close to the limit
Save workspace image to ~/.RData? [y/n/c]:

(note that the while() loop is just used because sometimes the error doesn't immediately show up during the first iteration).

This has been tested on two different Linux OS running different GDAL versions. By contrast, no such error is raised when running the same code on a Windows OS. Also, the error does not show up on Linux when

  • omitting the "-multi" option (which is my primary suspect);
  • disabling console output via quiet = TRUE;
  • executing the pure gdalwarp call on the command line, i.e. outside R.
utils::sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=de_DE.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9         rstudioapi_0.14    magrittr_2.0.3     units_0.8-0        tidyselect_1.1.2  
 [6] prompt_1.0.1       R6_2.5.1           rlang_1.0.5        fansi_1.0.3        dplyr_1.0.10      
[11] tools_4.2.1        parallel_4.2.1     grid_4.2.1         KernSmooth_2.23-20 utf8_1.2.2        
[16] cli_3.3.0          e1071_1.7-11       DBI_1.1.3          class_7.3-20       abind_1.4-5       
[21] lwgeom_0.2-8       tibble_3.1.8       lifecycle_1.0.1    sf_1.0-8           purrr_0.3.4       
[26] stars_0.5-6        vctrs_0.4.1        glue_1.6.2         proxy_0.4-27       compiler_4.2.1    
[31] pillar_1.8.1       generics_0.1.3     classInt_0.4-7     pkgconfig_2.0.3   
sf::sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H           PROJ 
      "3.10.2"        "3.5.1"        "9.0.1"         "true"         "true"        "9.0.1" 
@tim-salabim
Copy link
Member

I can reproduce this in both vanilla R and RStudio.

image

@edzer
Copy link
Member

edzer commented Sep 6, 2022

R is not a thread-safe application; the multi-thread call without quiet = TRUE will call Rprintf() in each thread (R output needs to use Rprintf() instead of printf(), so that things work on Win/OSX too), and this might then cause the error. With the quiet=TRUE there's no R code being called between starting & stopping of the threads.

@edzer edzer closed this as completed in e721547 Sep 6, 2022
edzer added a commit that referenced this issue Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants