I have a crash when I try to create a vtkPolyData. I guess this is a problem of the way I do things.
Here is my CMakelists:
>> cat CMakeLists.txt
cmake_minimum_required (VERSION 3.20)
# Define project
project(debugVTK)
# Find external library
find_package(VTK REQUIRED)
# Define binary
add_executable(debugVTK debugVTK.cpp)
target_include_directories(debugVTK PRIVATE "${VTK_INCLUDE_DIRS}")
target_link_libraries(debugVTK PRIVATE "${VTK_LIBRARIES}")
set_property(TARGET debugVTK PROPERTY CXX_STANDARD 20)
Here is the minimal code:
>> cat debugVTK.cpp
#include "vtkSmartPointer.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
int main () {
vtkSmartPointer<vtkPolyData> data;
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
data->SetPoints(points);
for (unsigned int i = 0; i < 5; i++) {
data->GetPoints()->InsertNextPoint(i+1, i+2, i+3);
}
}
Compilation works. But I get a crash at run time:
>> ./debugVTK
Segmentation fault
>> gdb --args ./debugVTK
Program received signal SIGSEGV, Segmentation fault.
0x00005555555561eb in main () at /tmp/debugVTK/debugVTK.cpp:8
8 data->SetPoints(points);
(gdb) l
3 #include "vtkPoints.h"
4
5 int main () {
6 vtkSmartPointer<vtkPolyData> data;
7 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
8 data->SetPoints(points);
9 for (unsigned int i = 0; i < 5; i++) {
10 data->GetPoints()->InsertNextPoint(i+1, i+2, i+3);
11 }
12 }
(gdb) p points
$1 = {<vtkSmartPointerBase> = {Object = 0x5555555cae00}, <No data fields>}
(gdb) p data
$2 = {<vtkSmartPointerBase> = {Object = 0x0}, <No data fields>}
why does the code crash? How to use vtkPolyData? (I guess I misuse it). Any help is appreciated;
Franck