<div dir="ltr">Thanks for your reply. Ok so this is the bug I remembered, in fact it happens all the time under gctorture(TRUE),<div>while inverting the order of:</div><div><br></div><div><div>RNGScope scope;</div><div><br>

</div><div>and</div><div><br></div><div>NumericMatrix out(10, 10);<br></div><div><div><br></div><div>makes it disappear.</div><div><br><div>At the moment all my packages use the form:</div><div><br></div><div>RcppExport SEXP myFun(){</div>

<div><br></div><div><span style="font-family:arial,sans-serif;font-size:13px">RNGScope scope;</span><br></div><div>...</div><div><br></div><div>} <br></div><div><br></div><div>should I then switch to the form:</div><div>
<br>
</div><div>\\ [[Rcpp::export]]</div><div><div>RcppExport SEXP myFun(){</div><div><br></div><div>\\ Not add RNGScope</div><div>...</div><div><br></div><div>} </div></div><div><br></div><div>? Maybe in the short term I'll just use the swapping trick! Strangely no error occurs if a NumericVector is returned.</div>

<div><br></div><div>Thanks,</div><div><br></div><div>Matteo</div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Aug 10, 2014 at 3:59 PM, JJ Allaire <span dir="ltr"><<a href="mailto:jj@rstudio.com" target="_blank">jj@rstudio.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Yes, there is a subtle bug in RNGScope which can cause this. The good news is that you don't need RNGScope (since it's added, along with a workaround for the bug, by Rcpp::export)<br>


<br></div><div><div class="h5"><div><br>On Aug 10, 2014, at 10:37 AM, Matteo Fasiolo <<a href="mailto:matteo.fasiolo@gmail.com" target="_blank">matteo.fasiolo@gmail.com</a>> wrote:<br><br></div><blockquote type="cite">

<div><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><font color="#000000" face="sans-serif">#include <Rcpp.h></font></div><div><font color="#000000" face="sans-serif">using namespace Rcpp;</font></div><div><font color="#000000" face="sans-serif"><br>




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




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




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


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


<div><font color="#000000" face="sans-serif"><br></font></div><div><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" target="_blank">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>
</div></blockquote></div></div><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Rcpp-devel mailing list</span><br><span><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a></span><br>


<span><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></span></div></blockquote></div>
</blockquote></div><br></div>