<br><br>Hello,<br><br>I have a code that uses VTK, but it can't run normally. As I have tried to solve the problem for two days but in vain and there is no one around me that familiar with VTK, I come here to look for help. Here is a piece of my code:<br><br>vtkUnstructuredGrid* VTKGrid;<br>template <typename T3, typename T4, typename T5> <br>        void UpdateVTKAttributes(T3& U_Field, T4& p_Field, T5& T_Field)<br>        {   <br>                if(VTKGrid->GetCellData()->GetArray("p") == NULL)<br>                {   <br>                        // pressure array<br>                        vtkNew<vtkDoubleArray> p;<br>                        p->SetName("p");<br>                        p->SetNumberOfComponents(1);<br>                        p->SetNumberOfTuples(static_cast<vtkIdType>(p_Field.size()));<br>                        VTKGrid->GetCellData()->AddArray(p.GetPointer());<br>                }   <br>                vtkDoubleArray* p = vtkDoubleArray::SafeDownCast(<br>                        VTKGrid->GetPointData()->GetArray("p"));<br>                vtkIdType numTuples = p->GetNumberOfTuples();<br><br>                int temp[400];<br>                for(vtkIdType i=0; i<numTuples; i++)<br>                {<br>                        //cout << p_Field[i] << " ";<br>                        //printf("%.15lf ", p_Field[i]);<br>                        //if((i+1) % 10 == 0)<br>                        //printf("\n");                          //these are OK<br><br>                        //temp[i] = p_Field[i];<br>                        //p->SetTuple1(i, temp[i]);     // fault<br><br>                        //printf("%lf ", p->GetTuple1(i));  //fault<br>                        //if((i+1) % 10 == 0)<br>                        //printf("\n");<br>                        //p->InsertTuple1(i, p_Field[i]);   //fault<br>                        //p->InsertNextTuple1(p_Field[i]);   //fault<br>                        p->SetTuple1(i, p_Field[i]);<br>                }<br>    }<br><br>When I run the executable file, I get segmentation fault:<br><br>#0  Foam::error::printStack(Foam::Ostream&) in "/opt/OpenFOAM/OpenFOAM-2.3.x/platforms/linux64IccDPOpt/lib/libOpenFOAM.so"<br>#1  Foam::sigSegv::sigHandler(int) in "/opt/OpenFOAM/OpenFOAM-2.3.x/platforms/linux64IccDPOpt/lib/libOpenFOAM.so"<br>#2  ? in "/lib64/libpthread.so.0"<br>#3  vtkDataArray::SetTuple1(long long, double) in "/pan20/yzzhang/paraview-5.2.0-release/lib/libvtkCommonCore-pv5.2.so.1"<br>#4  void Adaptor::CoProcess<Foam::DynamicList<float, 0u, 2u, 1u>, Foam::DynamicList<int, 0u, 2u, 1u>, Foam::DynamicList<float, 0u, 2u, 1u>, Foam::DynamicList<float, 0u, 2u, 1u>, Foam::DynamicList<float, 0u, 2u, 1u> >(Foam::DynamicList<float, 0u, 2u, 1u>&, Foam::DynamicList<int, 0u, 2u, 1u>&, Foam::DynamicList<float, 0u, 2u, 1u>&, Foam::DynamicList<float, 0u, 2u, 1u>&, Foam::DynamicList<float, 0u, 2u, 1u>&, unsigned int, bool) at ~/Desktop/myfoam/adaptor.h:90<br>#5  main at ~/Desktop/myfoam/runCatalyst.C:288<br>#6  __libc_start_main in "/lib64/libc.so.6"<br>#7  ? in "/root/Desktop/myfoam/OFcatalyst"<br>Segmentation fault (core dumped)<br><br><br>I'm think it is the statement "p->SetTuple1(i, p_Field[i]);" that causes the fault, and any other vtk function that references array p also causes the same fault. And, the same fault appears even without use of <i>for </i>loop. Just a single statement "  p->SetTuple1(0, p_Field[0]);" causes the fault. However, if I only print the p_Field without any reference of vtkDoubleArray p, the program runs with no fault. So I guess maybe the memory of array p was no allocated properly? I'm not sure.<br>Could you please tell me where the error is in that code? Thanks a lot!<br><br>sincerely<br>-Zhang<br><span></span><br><br><br>