Skip to content

Commit d91c39d

Browse files
authored
fix: dangling references when custom pointing (#530)
* fix: dangling references when custom pointing * feat: add a test * feat: add tests
1 parent 8ee514e commit d91c39d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/OpenSpaceToolkit/Astrodynamics/Flight/Profile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ Profile Profile::CustomPointing(
240240
const trajectory::Orbit& anOrbit, const std::function<Quaternion(const State&)>& anOrientationGenerator
241241
)
242242
{
243-
// Copy the orientation generator to avoid dangling references.
244-
auto dynamicProviderGenerator = [&anOrbit, anOrientationGenerator](const Instant& anInstant) -> Transform
243+
// Copy the orbit and orientation generator to avoid dangling references.
244+
auto dynamicProviderGenerator = [anOrbit, anOrientationGenerator](const Instant& anInstant) -> Transform
245245
{
246246
const State state = anOrbit.getStateAt(anInstant);
247247

test/OpenSpaceToolkit/Astrodynamics/Flight/Profile.test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,19 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Flight_Profile, CustomPointing)
10321032
EXPECT_TRUE(calculatedState.getAttitude().isNear(expectedState.getAttitude(), Angle::Arcseconds(1e-15)));
10331033
}
10341034
}
1035+
1036+
// Regression test for dangling orbit reference when a custom pointing profile
1037+
{
1038+
Profile profile = Profile::Undefined();
1039+
{
1040+
const Orbit anotherOrbit =
1041+
Orbit::SunSynchronous(epoch, Length::Kilometers(500.0), Time(6, 0, 0), earthSPtr);
1042+
1043+
profile = Profile::CustomPointing(anotherOrbit, alignmentTargetSPtr, clockingTargetSPtr);
1044+
}
1045+
1046+
EXPECT_NO_THROW(profile.getStateAt(epoch));
1047+
}
10351048
}
10361049

10371050
class OpenSpaceToolkit_Astrodynamics_Flight_Profile_Parametrized

0 commit comments

Comments
 (0)