[Rcpp-devel] My R package that passes CRAN tests crashes on Windows when using Rcpp code - only with antivirus software installed

Benjamin Blonder benjamin.blonder at ouce.ox.ac.uk
Wed Nov 1 16:47:10 CET 2017


I am writing with a very puzzling crash issue I have been unable to resolve
myself. It concerns my hypervolume R package, which uses Rcpp to call some
custom functions to build and evaluate a k-d tree data structure.
Everything has been working fine for several versions of the package, and
the package passes the CRAN tests.

The complication is on Windows. On a Windows 7/8/10 install, calling
functions via Rstudio, the package runs just fine. When using Windows
Rgui/Rscript, if antivirus software (e.g. Sophos or McAfee) is NOT
installed, the package also runs just fine. However on Windows with
antivirus and the Rgui/Rscript program, the package repeatably crashes the
entire program.

A minimally reproducible example is below:

library(hypervolume)
data(iris)
hv = hypervolume_svm(iris[,1:2])

On a debug trace, the problem occurs when hypervolume_svm() eventually
internally calls kdtree_ball_query_multiple(), which is just a wrapper for
an Rcpp call to a C++ function (in the package's src/convert.cpp):

SEXP kdtree_ball_query_multiple(SEXP tr, SEXP ptlist, SEXP nr, SEXP nc,
SEXP r, SEXP verb)

{

  XPtr<KDTree> tree = as<XPtr<KDTree> >(tr);

  int nrow = as<int>(nr);

  int ncol = as<int>(nc);

  NumericVector data(ptlist);

  double radius = as<double>(r);

  bool verbose = as<int>(verb);



  vector<vector< double > > dataMatrix

    = convertMatrixToVector(data.begin(), nrow, ncol);



  vector<int> finalCounts;



  if (ncol != tree->ndims())

  {

    throw(length_error("Points not same dimensionality as data in kdtree"));


  }



  RProgress::RProgress pb("[:bar]", nrow);

  if (verbose==1)

  {

    Rcpp::Rcout << "Ball query... \n";

    pb.tick(0);

  }



  for (int i=0; i<nrow; i++)

  {



    vector<int> thisIndices;

    vector<double> thisDistances;



    vector<double> thisPoint = dataMatrix[i];

    tree->ball_query(thisPoint, radius, thisIndices, thisDistances);



    // store the number of points within the ball for each point

    finalCounts.push_back(thisIndices.size());



    if (i%10==0 && verbose==1)

    {

      pb.update(1.0*(i+1)/nrow);

    }



  }



  if (verbose==1)

  {

    Rcpp::Rcout << "\ndone.\n";

  }



  pb.update(1);



  return(wrap(finalCounts));

}

As noted above, that same code works just fine on other platforms and has
worked well on Windows in other package versions too, with or without
antivirus.

Does anyone have any ideas for what is going on, or how to fix it? Are
there any other reports of antivirus programs causing this kind of crash,
or of Rcpp issues between Rstudio and Rgui or Rscript?

The problem is hard for me to debug as I only get user error reports and
have limited access to Windows machines with antivirus software - my test
environment has been Windows 7, no antivirus, in VirtualBox.

Code for the package is up at https://github.com/bblonder/hypervolume.

Thank you for your time!

Best wishes,
Benjamin Blonder

-- 
Benjamin Blonder
Environmental Change Institute
School of Geography and the Environment
University of Oxford

Website: http://www.benjaminblonder.org
Photo-blog (Natural Curiosities): http://bblonder.wordpress.com/
Google Scholar: http://scholar.google.com/citations?user=l3FNoE8AAAAJ
University of Arizona Sky School: https://skyschool.arizona.edu/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20171101/fbae2acf/attachment.html>


More information about the Rcpp-devel mailing list