ANTsX / ANTsRCore

Rcpp bindings for the C++ ANTs library used by the ANTsR package
9 stars 9 forks source link

antsAverageImages, new "weights" argument with no default #100

Closed dorianps closed 5 years ago

dorianps commented 5 years ago

Describe the bug Not sure how tests have passed on travis, but antsAverageImages seems to have a new weights argument with no default (here). I am getting strange segfaults and I am not sure exactly why, but the default example of antsAverageImage which calls the function without the weights argument should at least work and I don't see how can it work without defining weights. @muschellij2 can you pre-set the weights in the argument definition?

To Reproduce Steps to reproduce the behavior:

f1 = getANTsRData('r16')
f2 = getANTsRData('r64')
r16 <- antsImageRead(f1)
r64 <- antsImageRead(f2)
mylist <- list(r16, r64)
antsAverageImages(mylist)

Log:

> f1 = getANTsRData('r16')
> f2 = getANTsRData('r64')
> r16 <- antsImageRead(f1)
> r64 <- antsImageRead(f2)
> mylist <- list(r16, r64)
> antsAverageImages(mylist, weights=c(1,1)
+ )

 *** caught segfault ***
address (nil), cause 'memory not mapped'

 *** caught segfault ***

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: imageList[[1]] * 0
 2: imageList[[1]] * 0
 3: antsAverageImages(mylist, weights = c(1, 1))address (nil), cause 'memory not mapped'

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

Traceback:
Selection: 
Traceback:
 1:  1: imageList[[1]] * 0
 2: imageList[[1]] * 0
 3: antsAverageImages(mylist, weights = c(1, 1))

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
imageList[[1]] * 0
 2: Selection: imageList[[1]] * 0
 3: antsAverageImages(mylist, weights = c(1, 1))

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

Expected behavior No segfault, keep old behavior and accept images without weights for backward compatibility of existing scripts.

Screenshots None

Desktop (please complete the following information):

Additional context None

dorianps commented 5 years ago

Btw, I can see you check for missing input later: https://github.com/ANTsX/ANTsRCore/blob/master/R/antsAverageImages.R#L48-L49

But how is R accepting the function call with no default?

dorianps commented 5 years ago

Never mind, I just learned about missing. The segfault might be from other reasons.