C++ Array of ON_PointCloud

Dear @dale

I would like to ask how can I correctly create an array of pointclouds?

The code below crashes Rhino.
What I want to do is:

  1. Create n ON_PointCloud
  2. Iterate that array and insert points to that pointclouds based on “vector” called cluster.
  3. Bake the pointscloud to rhino.

This is my code that crash rhino, I am sure I am missing some basic C++ lessons:

   //allocate the array
   int n = groups.size();
   ON_PointCloud* arr = new ON_PointCloud[n];

   int counter = 0;
   for(auto it = cluster.begin(); it != cluster.end(); ++it) { //cluster is a vector of integeres
       int id = *it;
       ON_3dPoint p = *cloud->m_P.At(counter);
       arr[id].AppendPoint( p );

     //It already crashes here
     //Iterate pointclouds and add them to rhino
     for(int i = 0; i < n; i++){
        CRhinoPointCloudObject* cloudNew_obj = new CRhinoPointCloudObject();

       delete[] arr;

Hi @Petras_Vestartas,

Have you run a debug version of this? If you do, you should be able to find the crash without assistance.

– Dale

No, this is a hard part, because I am using a Release version and I cannot compile in Debug.

From your experience what could crash it at the first loop?

@Petras_Vestartas - In C++, a Debug plug-in build is just a Release build with Debug information.

Your Debug build configuration should link with the Release build of any 3rd party libraries you are linking with.

The debug away…

– Dale

Thanks, I did not know this, this would make my life much easier.

The id was sometimes -1, which gives error. Now it works, by detecting pointcloud clusters: