VTK Crash (through Point Cloud Library) - In vtkOpenGLIndexBufferObject::AppendPointIndexBuffer

Hi,

I’m trying to diagnose a crash I’m running into while drawing a point cloud using the PCL library.

The crash is happening in vtkOpenGLIndexBufferObject, in vtkOpenGLIndexBufferObject::AppendPointIndexBuffer. Specifically, this logic:

  size_t targetSize = indexArray.size() +
    cells->GetNumberOfConnectivityEntries() -
    cells->GetNumberOfCells();

I’m running into cases where GetNumberOfCells is larger than GetNumberOfConnectivityEntries. Since indexArray’s size is 0, this leads to a extremely large # given it is subtracting a larger number from a smaller number. And, as the code is trying to reserve this space in a vector, it fails and crashes.

Is this a logic error here? Any suggestions on how to diagnose this if GetNumberOfConnectivityEntries should be greater than GetNumberOfCells? I know it’s possible the bug can be in the point cloud library, but I’m pretty new to both, so I’m unsure where to look. Hoping some guidance from you guys will help me get to the bottom of things more quickly!

I can try to create an example showing the crash, but I figured I’d ask first. Using the point cloud library, I’m trying to draw a point cloud. The first few iterations of the point cloud draw fine, but then it crashes.

Some info about my setup:

  • Using VTK 8.2.0
  • Using PCL 1.9.1
  • On Windows 10, packages were installed through vcpkg if that matters…

Is that subtraction correct? Of course, I could be off base, but from my very limited understanding, that would make more sense. I’ve tried that and it does solve my crash issue.

Hi, I encountered the same problem recently and couldn’t find any reasonable explanation. However, my program was randomly crashing so I had to find a solution. I spent about 10 hours trying to figure out the reason behind this strange problem.

It turns out that there may be a bug in the updatePointCloud() method of pcl::visualization::PCLVisualizer. Namely, GetNumberOfCells() appears to not get updated. If you have a large point cloud and then you update the visualizer with a smaller point cloud using the same id, then GetNumberOfCells() may be larger than GetNumberOfConnectivityEntries() which should actually never happen if the point cloud is consistent.

My workaround, which also supports my observation, is to call removePointCloud() followed by addPointCloud() instead of updatePointCloud(). However, I am not an expert on PCL nor on VTK, so perhaps I am doing something wrong elsewhere and this is not a bug after all.

I have a really large project and currently no time to write a short example code to double check the issue, but perhaps this comment may be useful to others if they encounter the same issue.

I am using VTK 8.2.0 and PCL 1.9.1 under Ubuntu 18.04 and I am still using QVTKWidget instead of QVTKOpenGLWidget, so perhaps this issue is not there anymore when using QVTKOpenGLWidget.