Crash when computing difference for certain meshes
First of all, thank you very much for this library. We are trying to use it for creating surgical guides for fibula flap reconstructions and it seems to work very well for most of the cases.
Unfortunately, sometimes the code crashes in this line:
https://github.com/zippy84/vtkbool/blob/c0de9f68b41e53f71624dcf9aa3e4efddabfad4f/libs/vp/RmTrivials.cxx#L85
because _s vector is empty.
If you want to reproduce it: subtract DrillHole-dec.vtk from Plate-dec.vtk (the files are available here).
Do you have any suggestion for at least how to avoid the crash? Should we just add a if (!_s.empty()) {} check so that p.dir remains Dir::UNDEFINED?
After adding a _s.empty() check, I got an assert here:
https://github.com/zippy84/vtkbool/blob/c0de9f68b41e53f71624dcf9aa3e4efddabfad4f/libs/vp/RmTrivials.cxx#L355
because number of groups is 2. Replacing the assert with a if (grps.size() > 0) {} check "fixes" the crash but I'm not sure if this is the right thing to do.
Hi Andras.
At first I have to say, that the master version is not crash safe. It mostly crashes at this line:
https://github.com/zippy84/vtkbool/blob/c0de9f68b41e53f71624dcf9aa3e4efddabfad4f/vtkPolyDataBooleanFilter.cxx#L2854
Currently I'm working on a new version that fixes that. The lib is also not type-safe. There are many warnings when -Wconversion is enabled. My first changes could be found in the refactoring-branch, but it is not ready yet. The holes-merger an the decomposer are widely commented out.
I will take look for a solution of your issue.
Thank you for the quick response, looking forward to the fix.
We have found some additional issues (such as invalid comparator assert here because A>B and A<B did not provide consistent result), but if you are still working on some improvements then we'll hold this back until those get integrated.
Feel free to submit them now. Maybe it's already fixed.
https://github.com/zippy84/vtkbool/blob/c0de9f68b41e53f71624dcf9aa3e4efddabfad4f/vtkPolyDataBooleanFilter.cxx#L2854
Currently I'm working on a new version that fixes that.
Hi @zippy84,
Thank you very much for this library. I am trying to use boolean difference of this filter on my meshes. Most of the time it is working fine but some cases my program is crashing at the above mentioned line(#L2854 of vtkPolyDataBooleanFilter.cxx). I am using this filter in a loop and some times at the edge of the Sphere mesh if I do boolean diff operation I get an error message saying "Stripes are invalid" with some part of the mesh is left behind( Can see small parts of the mesh spiked at the edges in the attached image) and if I try to do difference operation on this area, then my program is crashing.
I see in this thread, you are already working on this issue. Do you have any suggestions to stop this crash until your fix is integrated into master branch?

@mallikarjun49 Can you supply two meshes that does not work?
@mallikarjun49 Can you supply two meshes that does not work?
Thank you very much for the quick response. I am basically using vtkSphereSource and vtkCylinderSource to do the difference operation. I am doing this operation in a loop. Basically my cylinder source translates to new position on key press and try to do difference operation on the output of the boolean filter in the previous step. //loop
{
auto booleanFilter = vtkSmartPointer<vtkPolyDataBooleanFilter>::New();
booleanFilter->SetInputData(0,polydata_);
booleanFilter->SetInputData(1,transformFilter_->GetOutput()); //cylinder translates to new position in each iteration
booleanFilter->SetOperModeToDifference();
booleanFilter->Update();
if(booleanFilter->GetOutput()->GetNumberOfCells() > 0)
{
polydata_->Initialize();
polydata_->DeepCopy(booleanFilter->GetOutput());
}
}
@mallikarjun49 export the meshes (polydata_ and transformFilter_->GetOutput()) to files, upload them somewhere, and post the download links here. It is not possible to reproduce the meshes exactly based on your approximate instructions.
Also note that vtkCylinderSource creates meshes that are very efficient for rendering but almost unusable for 3D modeling, because it creates extremely ill-shaped triangles (that span between the top and bottom planes of the cylinder). Use vtkLineSource and vtkTubeFilter instead, because with that you can create better shaped triangles.
@lassoan Thank you for your suggestions. I have now used vtkLineSource with vtkTubeFilter instead of vtkCylinderSource, and exported the mesh files. @zippy84 , Please find the attached source code files and the Mesh files for your reference. Source code should work as it is or with minor tweaks to CMakelists.txt.
I'm closing this as the code this refers to no longer exists.
Great! Thank you for working on it.
Thank you very much @zippy84 !!
