Read Access Violation in vtk3DLinearGridPlaneCutter::ProcessPiece() for VTK 9.0.0
I ran into a read access violation in VTK 9.0.0 if the filter pipeline is empty when vtkRenderer::ComputeVisiblePropBounds() is called (either directly by me or by the rendering code). I'll post the Call Stack and a proposed easy fix for this problem. Since this is deep in VTK, there's no way to catch the exception and prevent the application from crashing. The only option is to fix VTK.
Call Stack:
vtkCommonDataModel-9.0d.dll!vtkCellArray::Storage::Is64Bit()
vtkCommonDataModel-9.0d.dll!vtkCellArray::GetNumberOfCells()
vtkFiltersCore-9.0d.dll!vtk3DLinearGridPlaneCutter::ProcessPiece()
vtkFiltersCore-9.0d.dll!vtk3DLinearGridPlaneCutter::RequestData()
vtkCommonExecutionModel-9.0d.dll!vtkDataObjectAlgorithm::ProcessRequest()
vtkFiltersCore-9.0d.dll!vtkCutter::RequestData()
vtkCommonExecutionModel-9.0d.dll!vtkPolyDataAlgorithm::ProcessRequest()
vtkCommonExecutionModel-9.0d.dll!vtkExecutive::CallAlgorithm()
vtkCommonExecutionModel-9.0d.dll!vtkDemandDrivenPipeline::ExecuteData()
vtkCommonExecutionModel-9.0d.dll!vtkCompositeDataPipeline::ExecuteData()
vtkCommonExecutionModel-9.0d.dll!vtkDemandDrivenPipeline::ProcessRequest()
vtkCommonExecutionModel-9.0d.dll!vtkStreamingDemandDrivenPipeline::ProcessRequest()
vtkCommonExecutionModel-9.0d.dll!vtkCompositeDataPipeline::ForwardUpstream()
vtkCommonExecutionModel-9.0d.dll!vtkDemandDrivenPipeline::ProcessRequest()
vtkCommonExecutionModel-9.0d.dll!vtkStreamingDemandDrivenPipeline::ProcessRequest()
vtkCommonExecutionModel-9.0d.dll!vtkDemandDrivenPipeline::UpdateData()
vtkCommonExecutionModel-9.0d.dll!vtkStreamingDemandDrivenPipeline::Update()
vtkCommonExecutionModel-9.0d.dll!vtkStreamingDemandDrivenPipeline::Update()
vtkCommonExecutionModel-9.0d.dll!vtkAlgorithm::Update()
vtkCommonExecutionModel-9.0d.dll!vtkAlgorithm::Update()
vtkRenderingCore-9.0d.dll!vtkMapper::GetBounds()
vtkRenderingCore-9.0d.dll!vtkActor::GetBounds()
vtkRenderingCore-9.0d.dll!vtkAssembly::GetBounds()
vtkRenderingCore-9.0d.dll!vtkFrustumCoverageCuller::Cull()
vtkRenderingCore-9.0d.dll!vtkRenderer::AllocateTime()
vtkRenderingCore-9.0d.dll!vtkRenderer::Render()
vtkRenderingCore-9.0d.dll!vtkRendererCollection::Render()
vtkRenderingCore-9.0d.dll!vtkRenderWindow::DoStereoRender()
vtkRenderingCore-9.0d.dll!vtkRenderWindow::Render()
vtkRenderingOpenGL2-9.0d.dll!vtkOpenGLRenderWindow::Render()
vtkRenderingOpenGL2-9.0d.dll!vtkWin32OpenGLRenderWindow::MessageProc()
vtkRenderingOpenGL2-9.0d.dll!vtkWin32OpenGLRenderWindow::WndProc()
[External Code]
vtkRenderingUI-9.0d.dll!vtkHandleMessage2()
vtkRenderingUI-9.0d.dll!vtkHandleMessage()
[External Code]
My proposed easy fix in vtk3DLinearGridPlaneCutter.cxx is to change
int vtk3DLinearGridPlaneCutter::ProcessPiece(
vtkUnstructuredGrid* input, vtkPlane* plane, vtkPolyData* output)
{
// Make sure there is input data to process
vtkPoints* inPts = input->GetPoints();
vtkIdType numPts = inPts->GetNumberOfPoints();
vtkCellArray* cells = input->GetCells();
vtkIdType numCells = cells->GetNumberOfCells();
if (numPts <= 0 || numCells <= 0)
{
vtkLog(INFO, "Empty input");
return 0;
}
to be this (for more defensive programming)
int vtk3DLinearGridPlaneCutter::ProcessPiece(
vtkUnstructuredGrid* input, vtkPlane* plane, vtkPolyData* output)
{
// Make sure there is input data to process
vtkPoints* inPts = input->GetPoints();
vtkIdType numPts = inPts != nullptr ? inPts->GetNumberOfPoints() : 0;
vtkCellArray* cells = input->GetCells();
vtkIdType numCells = cells != nullptr ? cells->GetNumberOfCells() : 0;
if (numPts <= 0 || numCells <= 0)
{
vtkLog(INFO, "Empty input");
return 0;
}
I'm not sure about the logging of empty input, as that's a perfectly valid case IMHO, but that's not the point of this report.
Can someone apply this fix for the next release?