Fem: fix segmentation fault in FemPostDataAlongLineFilter::GetAxisData()

It's possible that pdata becomes a null pointer.
Forum thread: https://forum.freecadweb.org/viewtopic.php?f=18&t=67507
This commit is contained in:
wmayer
2022-03-27 19:18:33 +02:00
parent 42596f2f1b
commit 06aa45d7d4

View File

@@ -282,20 +282,24 @@ void FemPostDataAlongLineFilter::GetAxisData() {
const Base::Vector3d diff = vec1 - vec2;
double Len = diff.Length();
for(int i=0; i<dset->GetNumberOfPoints(); ++i) {
for (vtkIdType i = 0; i < dset->GetNumberOfPoints(); ++i) {
double value = 0;
if(pdata->GetNumberOfComponents() == 1)
value = pdata->GetComponent(i, component);
else {
for(int j=0; j<pdata->GetNumberOfComponents(); ++j)
value += std::pow(pdata->GetComponent(i, j),2);
if (pdata) {
if (pdata->GetNumberOfComponents() == 1) {
value = pdata->GetComponent(i, component);
}
else {
for (int j = 0; j < pdata->GetNumberOfComponents(); ++j)
value += std::pow(pdata->GetComponent(i, j), 2);
value = std::sqrt(value);
value = std::sqrt(value);
}
}
values.push_back(value);
double tcoord = tcoords->GetComponent(i, component);
coords.push_back(tcoord*Len);
coords.push_back(tcoord * Len);
}
YAxisData.setValues(values);
XAxisData.setValues(coords);