<div dir="ltr">Dear Rcpp developer,<div><br></div><div> I have experienced intermittent crashes of some of my</div><div>Rcpp function and I managed to reduce it to the following.</div><div><br></div><div>I build a package using <span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px">Rcpp.package.skeleton(), I delete</span></div>

<div><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px">all the files in the R and src folder, and I include in the src</span></div><div><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px">folder 2 files:</span></div>

<div><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px">####### exper.cpp</span></div><div><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px"><br>

</span></div><div><div style><font color="#000000" face="sans-serif">#include <Rcpp.h></font></div><div style><font color="#000000" face="sans-serif">using namespace Rcpp;</font></div><div style><font color="#000000" face="sans-serif"><br>

</font></div><div style><font color="#000000" face="sans-serif">// [[Rcpp::export]]</font></div><div style><font color="#000000" face="sans-serif">NumericMatrix exper( ) </font></div><div style><font color="#000000" face="sans-serif">{ </font></div>

<div style><font color="#000000" face="sans-serif">     RNGScope scope; </font></div><div style><font color="#000000" face="sans-serif">    </font></div><div style><font color="#000000" face="sans-serif">      NumericMatrix out(10, 10);</font></div>

<div style><font color="#000000" face="sans-serif">      </font></div><div style><font color="#000000" face="sans-serif">      return out;</font></div><div style><font color="#000000" face="sans-serif">            </font></div>

<div style><font color="#000000" face="sans-serif">}</font></div></div><div style><font color="#000000" face="sans-serif"><br></font></div><div style><font color="#000000" face="sans-serif">######### exper2.cpp</font></div>

<div style><font color="#000000" face="sans-serif"><br></font></div><div style><font color="#000000" face="sans-serif"><div>#include <Rcpp.h></div><div>using namespace Rcpp;</div><div><br></div><div>RcppExport SEXP exper2( ) </div>

<div>{ </div><div>      RNGScope scope;    </div><div><br></div><div>      NumericMatrix out(10, 10);</div><div>      </div><div>      return out;</div><div>            </div><div>}</div><div><br></div></font></div><div>
<span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px">The first version uses </span><span style="color:rgb(0,0,0);font-family:sans-serif">// [[Rcpp::export]] the second </span><span style="color:rgb(0,0,0);font-family:sans-serif">RcppExport.</span></div>

<div><span style="color:rgb(0,0,0);font-family:sans-serif">I then call </span><font color="#000000" face="sans-serif">compileAttributes(".") inside the package folder.</font></div><div><font color="#000000" face="sans-serif"><br>

</font></div><div><font color="#000000" face="sans-serif">Then I run:</font></div><div><font color="#000000" face="sans-serif"><br></font></div><div>#### test.R</div><div><font color="#000000" face="sans-serif"><br></font></div>

<div><font color="#000000" face="sans-serif"><div>library(anRpackage)</div><div>set.seed(4341)</div><div>for(ii in 1:500000){</div><div>  </div><div>  a <- .Call( "anRpackage_exper",  PACKAGE = "anRpackage" )</div>

<div>  </div><div>  matrix(a, 1, 100)</div><div>}</div><div><br></div><div>set.seed(4341)</div><div>for(ii in 1:500000){</div><div>  </div><div>  a <- .Call( "exper2",  PACKAGE = "anRpackage" )</div>

<div>  </div><div>  matrix(a, 1, 100)</div><div>}</div><div><br></div><div>exper2 crashes with:</div><div><br></div><div><div> *** caught segfault ***</div><div>address (nil), cause 'unknown'</div></div><div><br>
</div>
<div>Am I doing something wrong? </div><div><br></div><div>Removing the line "RNGScope scope;" solves the problem.</div><div><br></div><div>Maybe there is a relation with the problem found in this <a href="http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-May/005815.html">old discussion</a>?</div>

<div><br></div><div>Many thanks for you help.</div><div><br></div><div>Matteo</div></font></div><div><span style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px"><br></span></div></div>