From 2bb3635313e48162279562a811bd00111139ea9c Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Mon, 13 Jul 2026 22:32:12 +0200 Subject: [PATCH] Tie the external reaction and buoyancy properties only once FGExternalReactions::Load() and FGBuoyantForces::Load() are public and append to their force and cell lists, so either may be called more than once to add further items. My specific use case for this that an aircraft declares in or but then I need to add external forces from the C++ side which causes harmless errors because a second bind would log errors on the tied properties. --- src/models/FGBuoyantForces.cpp | 6 +++++- src/models/FGBuoyantForces.h | 1 + src/models/FGExternalReactions.cpp | 8 +++++++- src/models/FGExternalReactions.h | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/models/FGBuoyantForces.cpp b/src/models/FGBuoyantForces.cpp index de0e2baac2..bfa830b716 100644 --- a/src/models/FGBuoyantForces.cpp +++ b/src/models/FGBuoyantForces.cpp @@ -130,8 +130,12 @@ bool FGBuoyantForces::Load(Element *document) PostLoad(document, FDMExec); - if (!NoneDefined) { + // Load() is public and appends to the cell list, so it may be called more than + // once to add further gas cells. The properties must only be tied the first + // time: tying them again fails and logs an error for each one. + if (!NoneDefined && !isBound) { bind(); + isBound = true; } return true; diff --git a/src/models/FGBuoyantForces.h b/src/models/FGBuoyantForces.h index 3cdda4bcbb..efd62e92ab 100644 --- a/src/models/FGBuoyantForces.h +++ b/src/models/FGBuoyantForces.h @@ -178,6 +178,7 @@ class FGBuoyantForces : public FGModel FGColumnVector3 vXYZgasCell_arm; // [lbs in] bool NoneDefined; + bool isBound = false; void bind(void); diff --git a/src/models/FGExternalReactions.cpp b/src/models/FGExternalReactions.cpp index b58e9f9ffe..606e9dc126 100644 --- a/src/models/FGExternalReactions.cpp +++ b/src/models/FGExternalReactions.cpp @@ -85,7 +85,13 @@ bool FGExternalReactions::Load(Element* el) PostLoad(el, FDMExec); - if (!Forces.empty()) bind(); + // Load() is public and may be called more than once to add further forces, so + // the properties must only be tied the first time. Tying them again fails and + // logs an error for each one. + if (!Forces.empty() && !isBound) { + bind(); + isBound = true; + } return true; } diff --git a/src/models/FGExternalReactions.h b/src/models/FGExternalReactions.h index 765ebb54a7..18d4652a72 100644 --- a/src/models/FGExternalReactions.h +++ b/src/models/FGExternalReactions.h @@ -169,6 +169,7 @@ class FGExternalReactions : public FGModel //unsigned int numForces; FGColumnVector3 vTotalForces; FGColumnVector3 vTotalMoments; + bool isBound = false; void bind(void); void Debug(int from) override;