From bf72e1d7290be03f943df4e4940f38c751e34b22 Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Thu, 7 May 2020 11:07:47 +0100
Subject: [PATCH] Fix for reposition crash for some users
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Speculative fix for a reposition assert which Huntley is seeing:
  https://sourceforge.net/p/flightgear/codetickets/2229/

Unclear why it’s not happening for me other some other folks, but this
should logically be the correct fix. Let’s find out.
---
 src/Autopilot/autopilotgroup.cxx | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/Autopilot/autopilotgroup.cxx b/src/Autopilot/autopilotgroup.cxx
index 2fe2a1ce1..39680dfb8 100644
--- a/src/Autopilot/autopilotgroup.cxx
+++ b/src/Autopilot/autopilotgroup.cxx
@@ -106,7 +106,12 @@ void FGXMLAutopilotGroupImplementation::reinit()
 {
   SGSubsystemGroup::unbind();
   clearSubsystems();
-
+  
+  // ensure we bind again, so the SGSubsystemGroup state is correct before
+  // we call init. Since there's no actual group members at this point (we
+  // cleared them just above) this is purely to ensure SGSubsystemGroup::_state
+  // is BIND, so that ::init doesn't assert
+  SGSubsystemGroup::bind();
   init();
 }