<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p><br>
</p>
<meta content="text/html; charset=UTF-8">
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>I was finally able to get reproducible, although likely not minimal segfault even without Rstudio.  I built a new package and running a weird loop with rebuilding of the source files and doing some other random stuff as well, I was able to get a segfault.
 valgrind output looks like this:</p>
<pre><code><span style="font-size: 8pt;">==26398== Jump to the invalid address stated on the next line
==26398==    at 0x1DD75010: ???
==26398==    by 0x4F7D026: R_RunWeakRefFinalizer (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F7D213: ??? (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F4A679: Rf_eval (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F4EA11: ??? (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F4AB99: Rf_eval (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F4D723: ??? (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F4AA9F: Rf_eval (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F4CABE: ??? (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F42F67: ??? (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F50D55: ??? (in /usr/lib/R/lib/libR.so)
==26398==    by 0x4F512FF: ??? (in /usr/lib/R/lib/libR.so)
==26398==  Address 0x1dd75010 is not stack'd, malloc'd or (recently) free'd
==26398== 

 *** caught segfault ***
address 0x1dd75010, cause 'memory not mapped'
An irrecoverable exception occurred. R is aborting now ...
==26398== 
==26398== Process terminating with default action of signal 11 (SIGSEGV)
==26398==    at 0x547451D: raise (raise.c:53)
==26398==    by 0x547466F: ??? (in /lib/x86_64-linux-gnu/libpthread-2.24.so)
==26398==    by 0x1DD7500F: ???
==26398== 
==26398== HEAP SUMMARY:
==26398==     in use at exit: 259,162,338 bytes in 28,465 blocks
==26398==   total heap usage: 315,728 allocs, 287,263 frees, 1,311,929,706 bytes allocated
==26398== 
==26398== LEAK SUMMARY:
==26398==    definitely lost: 0 bytes in 0 blocks
==26398==    indirectly lost: 0 bytes in 0 blocks
==26398==      possibly lost: 0 bytes in 0 blocks
==26398==    still reachable: 259,162,338 bytes in 28,465 blocks
==26398==                       of which reachable via heuristic:
==26398==                         newarray           : 4,264 bytes in 1 blocks
==26398==         suppressed: 0 bytes in 0 blocks
==26398== Reachable blocks (those to which a pointer was found) are not shown.
==26398== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==26398== 
==26398== For counts of detected and suppressed errors, rerun with: -v
==26398== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)</span>
</code></pre>
<p>What is super weird is that currently I have this extra C++ function which is not even used at all:</p>
<pre><code><span style="font-size: 8pt;">double log_prior_pdf(const arma::vec& theta) {

  double log_pdf = 0.0;
  double infinite = -arma::datum::inf; //comment out this line and everything works??
  return log_pdf;
}</span></code></pre>
If I remove the middle line, I seem to get rid of the segfault. <span>However, I also have some extra stuff on the R script (crash.R) as well which looks to be necessary for the segfault to trigger at certain point (third iteration of the outer loop).</span></div>
<br>
<div dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<br>
<p>Jouni<br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>Lähettäjä:</b> Dirk Eddelbuettel <dirk.eddelbuettel@gmail.com> käyttäjän Dirk Eddelbuettel <edd@debian.org> puolesta<br>
<b>Lähetetty:</b> maanantai 4. syyskuuta 2017 15.32.13<br>
<b>Vastaanottaja:</b> Helske, Jouni<br>
<b>Kopio:</b> Rcpp-devel@lists.r-forge.r-project.org<br>
<b>Aihe:</b> Re: [Rcpp-devel] Rstudio crashes with repeated calls to sourceCpp with Xptr export</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText"><br>
Hi Jouni,<br>
<br>
On 4 September 2017 at 08:22, Helske, Jouni wrote:<br>
| In the bssm package (<a href="https://github.com/helske/bssm" id="LPlnk400281" previewremoved="true">https://github.com/helske/bssm</a>), I let the users<br>
| define a state space model via own C++ functions which are then exported as<br>
| Xptr to R side, and passed back to C++ function for SMC/MCMC etc. Normally<br>
| this works fine, but when user repeatedly modifies the model functions and<br>
| re-exports them via repeated calls sourceCpp, sometimes whole Rstudio<br>
| crashes.<br>
<br>
Which version of RStudio?  See Help -> About<br>
<br>
| I haven't been able to pinpoint the reason or minimal example. Have anyone else experienced similar issues or is it just me i.e. error in my own implementations?<br>
<br>
There are a lot of dependencies here [re-indented by me]:<br>
<br>
  Suggests: KFAS (>= 1.2.1), knitr (>= 1.11), rmarkdown (>= 0.8.1), testthat,<br>
     bayesplot<br>
  Imports: coda (>= 0.18-1), diagis, ggplot2 (>= 2.0.0), Rcpp (>= 0.12.3)<br>
  LinkingTo: BH, Rcpp, RcppArmadillo, ramcmc, sitmo<br>
<br>
We do know Boost interactions (between code compiled 'by us' as R extensions<br>
using Boost, and RStudio itself also using an older version of Boost) had<br>
thrown spanners in the past. A while back Kevin updated RStudio internals and<br>
shielded "their" Boost better.<br>
<br>
I happen to run RStudio "Daily" builds on all my machines -- those have the<br>
fix and "behave". Maybe worth a try for you.<br>
 <br>
| Simplest case of this is the discretized SDE models, this is the function<br>
| which user modifies:<br>
| <a href="https://github.com/helske/bssm/blob/master/vignettes/sde_functions.cpp" id="LPlnk406661" previewremoved="true">
https://github.com/helske/bssm/blob/master/vignettes/sde_functions.cpp</a>,
<div id="LPBorder_GT_15045495828150.9303402421277678" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_15045495828080.7680799617515849" style="width: 90%; background-color: rgb(255, 255, 255); position: relative; overflow: auto; padding-top: 20px; padding-bottom: 20px; margin-top: 20px; border-top: 1px dotted rgb(200, 200, 200); border-bottom: 1px dotted rgb(200, 200, 200);" cellspacing="0">
<tbody>
<tr style="border-spacing: 0px;" valign="top">
<td id="ImageCell_15045495828100.5396137853352901" style="width: 250px; position: relative; display: table-cell; padding-right: 20px;" colspan="1">
<div id="LPImageContainer_15045495828110.9707410659177389" style="background-color: rgb(255, 255, 255); height: 250px; position: relative; margin: auto; display: table; width: 250px;">
<a id="LPImageAnchor_15045495828110.8463423242320118" style="display: table-cell; text-align: center;" href="https://github.com/helske/bssm/blob/master/vignettes/sde_functions.cpp" target="_blank"><img style="display: inline-block; max-width: 250px; max-height: 250px; height: 250px; width: 250px; border-width: 0px; vertical-align: bottom;" aria-label="Linkin esikatselukuva valittu. Avaa linkki kaksoisnapauttamalla." id="LPThumbnailImageID_15045495828120.5446565755368848" width="250" height="250" src="https://avatars2.githubusercontent.com/u/1560448?v=4&s=400"></a></div>
</td>
<td id="TextCell_15045495828130.6862508737875254" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;" colspan="2">
<div id="LPRemovePreviewContainer_15045495828130.6387520431844096"></div>
<div id="LPTitle_15045495828130.3824510939012491" style="top: 0px; color: rgb(0, 120, 215); font-weight: 400; font-size: 21px; font-family: "wf_segoe-ui_light","Segoe UI Light","Segoe WP Light","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; line-height: 21px;">
<a id="LPUrlAnchor_15045495828140.23892202048038358" style="text-decoration: none;" href="https://github.com/helske/bssm/blob/master/vignettes/sde_functions.cpp" target="_blank">bssm/sde_functions.cpp at master · helske/bssm · GitHub</a></div>
<div id="LPMetadata_15045495828140.5340400338186864" style="margin: 10px 0px 16px; color: rgb(102, 102, 102); font-weight: 400; font-family: "wf_segoe-ui_normal","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; font-size: 14px; line-height: 14px;">
github.com</div>
<div id="LPDescription_15045495828150.9668539845119711" style="display: block; color: rgb(102, 102, 102); font-weight: 400; font-family: "wf_segoe-ui_normal","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; font-size: 14px; line-height: 20px; max-height: 100px; overflow: hidden;">
bssm - Bayesian Inference of State Space Models</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
| <<a href="https://github.com/helske/bssm/blob/master/vignettes/sde_functions.cpp" id="LPlnk150119" previewremoved="true">https://github.com/helske/bssm/blob/master/vignettes/sde_functions.cpp</a>>
<div id="LPBorder_GT_15045495830660.41924587621249476" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_15045495830620.41361984494736304" style="width: 90%; background-color: rgb(255, 255, 255); position: relative; overflow: auto; padding-top: 20px; padding-bottom: 20px; margin-top: 20px; border-top: 1px dotted rgb(200, 200, 200); border-bottom: 1px dotted rgb(200, 200, 200);" cellspacing="0">
<tbody>
<tr style="border-spacing: 0px;" valign="top">
<td id="ImageCell_15045495830630.4705765436671645" style="width: 250px; position: relative; display: table-cell; padding-right: 20px;" colspan="1">
<div id="LPImageContainer_15045495830630.2968625400672452" style="background-color: rgb(255, 255, 255); height: 250px; position: relative; margin: auto; display: table; width: 250px;">
<a id="LPImageAnchor_15045495830630.032458290440198434" style="display: table-cell; text-align: center;" href="https://github.com/helske/bssm/blob/master/vignettes/sde_functions.cpp" target="_blank"><img style="display: inline-block; max-width: 250px; max-height: 250px; height: 250px; width: 250px; border-width: 0px; vertical-align: bottom;" aria-label="Linkin esikatselukuva valittu. Avaa linkki kaksoisnapauttamalla." id="LPThumbnailImageID_15045495830630.1889715101010353" width="250" height="250" src="https://avatars2.githubusercontent.com/u/1560448?v=4&s=400"></a></div>
</td>
<td id="TextCell_15045495830650.03551600491021534" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;" colspan="2">
<div id="LPRemovePreviewContainer_15045495830650.04113922412304194"></div>
<div id="LPTitle_15045495830650.10282662336957815" style="top: 0px; color: rgb(0, 120, 215); font-weight: 400; font-size: 21px; font-family: "wf_segoe-ui_light","Segoe UI Light","Segoe WP Light","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; line-height: 21px;">
<a id="LPUrlAnchor_15045495830650.007485300350805635" style="text-decoration: none;" href="https://github.com/helske/bssm/blob/master/vignettes/sde_functions.cpp" target="_blank">bssm/sde_functions.cpp at master · helske/bssm · GitHub</a></div>
<div id="LPMetadata_15045495830660.7000485281340755" style="margin: 10px 0px 16px; color: rgb(102, 102, 102); font-weight: 400; font-family: "wf_segoe-ui_normal","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; font-size: 14px; line-height: 14px;">
github.com</div>
<div id="LPDescription_15045495830660.9440989152092686" style="display: block; color: rgb(102, 102, 102); font-weight: 400; font-family: "wf_segoe-ui_normal","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; font-size: 14px; line-height: 20px; max-height: 100px; overflow: hidden;">
bssm - Bayesian Inference of State Space Models</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
| and the relevant parts of the package codes are in src/function_pointers.h,<br>
| src/sde_ssm.cpp and src/R_sde.cpp (I don't really expect anyone to read<br>
| through all of these).<br>
<br>
We'd probably need a reproducible example to really help.<br>
<br>
Dirk<br>
<br>
-- <br>
<a href="http://dirk.eddelbuettel.com" id="LPlnk677532" previewremoved="true">http://dirk.eddelbuettel.com</a> | @eddelbuettel | edd@debian.org<br>
</div>
</span></font></div>
</body>
</html>