From 88aef8caf8702eb1478eea8741b8b40dc4b5203f Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 16 Nov 2013 11:59:23 +0000 Subject: [PATCH] Reset: guard against picks during re-init --- src/Input/FGMouseInput.cxx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Input/FGMouseInput.cxx b/src/Input/FGMouseInput.cxx index 545c9890e..6d052c881 100644 --- a/src/Input/FGMouseInput.cxx +++ b/src/Input/FGMouseInput.cxx @@ -154,6 +154,7 @@ class FGMouseInput::FGMouseInputPrivate : public SGPropertyChangeListener { public: FGMouseInputPrivate() : + initialized(false), haveWarped(false), xSizeNode(fgGetNode("/sim/startup/xsize", false ) ), ySizeNode(fgGetNode("/sim/startup/ysize", false ) ), @@ -325,6 +326,7 @@ public: mouse mice[MAX_MICE]; + bool initialized; bool hideCursor, haveWarped; bool tooltipTimeoutDone; bool clickTriggersTooltip; @@ -376,6 +378,14 @@ FGMouseInput::~FGMouseInput() void FGMouseInput::init() { + if (d->initialized) { + SG_LOG(SG_INPUT, SG_WARN, "Duplicate init of FGMouseInput"); + + return; + } + + d->initialized = true; + SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings"); std::string module = ""; @@ -461,6 +471,10 @@ void FGMouseInput::init() void FGMouseInput::update ( double dt ) { + if (!d->initialized) { + SG_LOG(SG_INPUT, SG_WARN, "update of mouse before init"); + } + mouse &m = d->mice[0]; int mode = m.mode_node->getIntValue(); if (mode != m.current_mode) { @@ -540,6 +554,11 @@ mouse_mode::~mouse_mode () void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea) { + if (!d->initialized) { + // can occur during reset + return; + } + int modifiers = fgGetKeyModifiers(); mouse &m = d->mice[0]; @@ -681,6 +700,11 @@ void FGMouseInput::processMotion(int x, int y, const osgGA::GUIEventAdapter* ea) void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea) { + if (!d->initialized) { + // can occur during reset + return; + } + mouse &m = d->mice[0]; if (m.current_mode < 0 || m.current_mode >= m.nModes) { -- 2.39.5