Skip to content

Commit

Permalink
Merge pull request #984 from DLR-SC/962-bug-hard-crash-with-no-guidec…
Browse files Browse the repository at this point in the history
…urves

Fix for hard crash if guiceCurves node is present but empty in wing segment
  • Loading branch information
AntonReiswich authored Jan 2, 2024
2 parents 7671d7e + 5c645fc commit ec63eee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/guide_curves/CCPACSGuideCurves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ bool CCPACSGuideCurves::GuideCurveExists(std::string uid) const
std::vector<double> CCPACSGuideCurves::GetRelativeCircumferenceParameters() const
{
std::vector<double> relCircs;

// CPACS 3.3 requires guideCurves to be present. To prevent a hard crash if this is NOT the case,
// we shoud exit here (or at least before the call to relCircs.back())
if (GetGuideCurveCount() == 0) {
return relCircs;
}

for (int iguide = 1; iguide <= GetGuideCurveCount(); ++iguide) {
const CCPACSGuideCurve* root = GetGuideCurve(iguide).GetRootCurve();
relCircs.push_back(*root->GetFromRelativeCircumference_choice2());
Expand Down
27 changes: 27 additions & 0 deletions tests/unittests/tiglWingGuideCurves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,30 @@ TEST_F(WingGuideCurve, bug975)
}

}


TEST_F(WingGuideCurve, bug962)
{
//https://github.com/DLR-SC/tigl/issues/962

TixiDocumentHandle tixi_h;
TiglCPACSConfigurationHandle tigl_h;

// open simpletest with tixi and add empty guidecurves node
const char* filename = "TestData/simpletest.cpacs.xml";
auto tixiRet = tixiOpenDocument(filename, &tixi_h);
ASSERT_EQ (tixiRet, SUCCESS);
tixiRet = tixiCreateElement(tixi_h, "/cpacs/vehicles/aircraft/model/wings/wing[1]/segments/segment[1]", "guideCurves");
ASSERT_EQ (tixiRet, SUCCESS);

// open with tigl and try to build segment loft
auto tiglRet = tiglOpenCPACSConfiguration(tixi_h, "Cpacs2Test", &tigl_h);
ASSERT_EQ(tiglRet, TIGL_SUCCESS);


tigl::CCPACSConfigurationManager& manager = tigl::CCPACSConfigurationManager::GetInstance();
tigl::CCPACSConfiguration& config = manager.GetConfiguration(tigl_h);
tigl::CCPACSWing& wing = config.GetWing(1);
tigl::CCPACSWingSegment& segment1 = wing.GetSegment(1);
segment1.GetLoft();
}

0 comments on commit ec63eee

Please sign in to comment.