I would say you should create a simpler example that still crashes. Comment out 
everything except the first for loop; see if it crashes then. If not, uncomment 
the next one, etc. Repeat this until you find where it crashes.

Do you have a one-off problem with a loop index? I think you do, but will let 
you look into this yourself.

On Jun 22, 2013, at 12:10 PM, Marc Jekel <[email protected]> wrote:

> Dear Rcpp users,
> 
> I am a beginner, I was inspired by the new book by Eddelbuettel and just 
> started to use Rccp. So far, everything works fine except for one function. 
> The strange thing about it is that I runs perfectly when I call it several 
> times but crashes my R session at some point (usually after the third call). 
> I checked it on two Win 8 PCS to make sure it is nothing related to my PC.
> 
> Here is the code:
> 
> ##########
> 
> #include <Rcpp.h>
> using namespace Rcpp;
> 
> // [[Rcpp::export]]
> NumericMatrix transPCSpairwiseComp_C(
> NumericVector validities,
> NumericMatrix pattern,
> int numbCues
> ){
> 
> NumericMatrix weightsNet(numbCues+3,numbCues+3);
> 
> for(int loop = 0; loop < numbCues; loop++){
> 
>  weightsNet(0,1+loop) = validities[loop];
> }
> 
> for(int loopCol = 0; loopCol < numbCues; loopCol++){
> for(int loop = 0; loop < numbCues; loop++){
> weightsNet(1+loopCol, numbCues + 1 + loop)=
> pattern(loopCol,loop);
> 
> }}
> 
> weightsNet(numbCues+1, numbCues+1) = 0;
> weightsNet(numbCues+1, numbCues+2) = -.2;
> 
> for(int LoopCol = 0; LoopCol < weightsNet.nrow(); LoopCol++){
> for(int LoopRow = 0; LoopRow < weightsNet.nrow(); LoopRow++){
> weightsNet(LoopCol,LoopRow) = weightsNet(LoopCol,LoopRow) + 
> weightsNet(LoopRow,LoopCol);
> }}
> 
> 
> return weightsNet;
> }
> 
> #########
> 
> So it is very basic code, a matrix is created based on three inputs (the 
> vector "validities", the matrix "pattern", and the integer "numbCues"). My 
> impression is that the very first command (creating the matrix weightsNet) is 
> problematic because R also crashes when I delete all other code (although 
> usually not after the third time I call it).
> 
> Thanks for any hint!
> 
> Marc
> 
> 
> 
> _______________________________________________
> Rcpp-devel mailing list
> [email protected]
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to