From 3cb05a920792c23c03bf27023777e4cf1c8c32f6 Mon Sep 17 00:00:00 2001
From: Erik Hofman <erik@ehofman.com>
Date: Thu, 12 Mar 2020 10:31:38 +0100
Subject: [PATCH] Do not try to initialize all 16 joysticks every frame if they
 where not found previously. Try it once every second instead.

---
 src/Input/FGJoystickInput.cxx | 6 +++++-
 src/Input/FGJoystickInput.hxx | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/Input/FGJoystickInput.cxx b/src/Input/FGJoystickInput.cxx
index 1144fca99..979664c55 100644
--- a/src/Input/FGJoystickInput.cxx
+++ b/src/Input/FGJoystickInput.cxx
@@ -344,7 +344,11 @@ void FGJoystickInput::updateJoystick(int index, FGJoystickInput::joystick* joy,
   if (js == 0 || js->notWorking()) {
     joysticks[index].initializing = true;
     if (js) {
-      joysticks[index].plibJS.reset( new jsJoystick(index) );
+      joysticks[index].init_dt += dt;
+      if (joysticks[index].init_dt >= 1.0) {
+        joysticks[index].plibJS.reset( new jsJoystick(index) );
+        joysticks[index].init_dt = 0.0;
+      }
     }
     return;
   }
diff --git a/src/Input/FGJoystickInput.hxx b/src/Input/FGJoystickInput.hxx
index 247225575..c2d6239b5 100644
--- a/src/Input/FGJoystickInput.hxx
+++ b/src/Input/FGJoystickInput.hxx
@@ -104,6 +104,7 @@ private:
       bool initializing = true;
       bool initialized = false;
       float values[MAX_JOYSTICK_AXES];
+      double init_dt = 0.0f;
 
       void clearAxesAndButtons();
     };