Rendering PointHandleRepresentation2D with cursor type cause crash!

Just run the following codes, you’ll get a nullptr issue. If the PointHandleRepresentation2D doesn’t have an input cursor type, which means , just comment this line code : handleRep->SetCursorShape(cursor2D->GetOutput()); ,no crash. Can VTK experts shed some lights on this? Thanks!
int main(int, char *[])
{
// Create the RenderWindow, Renderer and both Actors
//
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);

vtkRegularPolygonSource *cursor2D = vtkRegularPolygonSource::New();
cursor2D->SetNumberOfSides(20);
cursor2D->GeneratePolygonOn();
cursor2D->SetRadius(23);
vtkPointHandleRepresentation2D *handleRep = vtkPointHandleRepresentation2D::New();
double *pos = new double[3]{ 80, 80, 40 };
handleRep->SetWorldPosition(pos);
handleRep->ActiveRepresentationOn();
handleRep->PickableOn();
handleRep->SetHandleSize(18);
handleRep->SetCursorShape(cursor2D->GetOutput());

vtkHandleWidget *handleWidget = vtkHandleWidget::New();
handleWidget->SetInteractor(iren);
handleWidget->SetRepresentation(handleRep);

ren1->SetBackground(0.1, 0.2, 0.4);
renWin->SetSize(300, 300);

handleWidget->ProcessEventsOn();
handleWidget->On();
iren->Initialize();
renWin->Render();

//iren->Start();

return EXIT_SUCCESS;

}

  cursor2D->Update();

will fix the crash. However there are other problems.

  1. VTK has excellent inbuilt reference counting so I think you should first rewrite your code using vtkNew. Once you have done this all the references will be handled automatically.
  2. You’ll need to figure how use the widgets.

There are plenty of examples e.g. VTKExamples, (no longer active) mainly using vtkSmartPointer and a test site vtk-examples using modernised versions of the code from the previously referred site, mainly using vtkNew. In both these sites, there are examples using Widgets.

To get you started I have rewritten your code: main.zip (1.4 KB)