为VTK修复vtkOBJReader的一个segfault
Background 测试用PyTorch3D生成的Mesh时,打算用VTK对Mesh做离屏渲染生成图片,结果发现VTK的python binding和C++库都会在vtkOBJReader::Update时崩溃。由于是AI模型生成的OBJ文件,OBJ本身是有可能不太标准的,但用Blender、Open3D、trimesh测试,发现都可以加载该文件。看起来似乎VTK的vtkOBJReader实现不够健壮,遂决定调试一番。 Debug 以导致问题的OBJ文件编写复现demo,目录结构: $ tree . . ├── assets │ ├── rand_0_diffuse.png │ ├── rand_0_normal.png │ ├── rand_0_skin.mtl │ ├── rand_0_skin.obj │ └── rand_0_spec.png ├── CMakeLists.txt └── main.cpp main.cpp: #include <vtkOBJReader.h> int main() { vtkNew<vtkOBJReader> reader; reader->SetFileName("rand_0_skin.obj"); reader->Update(); return 0; } 崩溃堆栈: 1 vtkAOSDataArrayTemplate<float>::GetTuple vtkAOSDataArrayTemplate.txx 275 0x7ffff6ee05e5 2 vtkOBJReader::RequestData vtkOBJReader.cxx 978 0x7ffff7b4c793 3 vtkPolyDataAlgorithm::ProcessRequest vtkPolyDataAlgorithm.cxx 87 0x7ffff28aaec6 4 vtkExecutive::CallAlgorithm vtkExecutive.cxx 734 0x7ffff287faf9 5 vtkDemandDrivenPipeline::ExecuteData vtkDemandDrivenPipeline.cxx 461 0x7ffff2876004 6 vtkCompositeDataPipeline::ExecuteData vtkCompositeDataPipeline....