1
0
Fork 0

FGMouseInput: add shutdown() and reinit() overrides

- Modify global_mouseInput in init() and in shutdown(), because *these*
  are the places where FGMouseInput is enabled or disabled.

- reinit() does shutdown() followed by init().

Note: the commented-out block starting with "FIXME: memory leak" that is
      removed here was just an outdated comment, because SGBindingList
      is an std::vector<SGBinding_ptr>, where SGBinding_ptr is a smart
      pointer type (SGSharedPtr<SGBinding>). In other words, there was
      no leak in this place---at least, not recently.
This commit is contained in:
Florent Rougon 2018-01-14 00:00:28 +01:00
parent 2eb583e9e1
commit 99c809dda0
2 changed files with 25 additions and 27 deletions

View file

@ -111,7 +111,7 @@ void ActivePickCallbacks::update( double dt, unsigned int keyModState )
*/ */
struct mouse_mode { struct mouse_mode {
mouse_mode (); mouse_mode ();
virtual ~mouse_mode ();
FGMouseCursor::Cursor cursor; FGMouseCursor::Cursor cursor;
bool constrained; bool constrained;
bool pass_through; bool pass_through;
@ -347,7 +347,7 @@ public:
// The Mouse Input Implementation // The Mouse Input Implementation
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
static FGMouseInput* global_mouseInput = NULL; static FGMouseInput* global_mouseInput = nullptr;
static void mouseClickHandler(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea) static void mouseClickHandler(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea)
{ {
@ -361,21 +361,12 @@ static void mouseMotionHandler(int x, int y, const osgGA::GUIEventAdapter* ea)
global_mouseInput->doMouseMotion(x, y, ea); global_mouseInput->doMouseMotion(x, y, ea);
} }
FGMouseInput::FGMouseInput() = default;
FGMouseInput::FGMouseInput()
{
global_mouseInput = this;
}
FGMouseInput::~FGMouseInput()
{
global_mouseInput = NULL;
}
void FGMouseInput::init() void FGMouseInput::init()
{ {
SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings"); SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
d.reset(new FGMouseInputPrivate()); d.reset(new FGMouseInputPrivate());
std::string module = ""; std::string module = "";
@ -457,6 +448,23 @@ void FGMouseInput::init()
fgRegisterMouseClickHandler(mouseClickHandler); fgRegisterMouseClickHandler(mouseClickHandler);
fgRegisterMouseMotionHandler(mouseMotionHandler); fgRegisterMouseMotionHandler(mouseMotionHandler);
global_mouseInput = this;
}
void FGMouseInput::shutdown()
{
SG_LOG(SG_INPUT, SG_DEBUG, "Shutting down mouse bindings");
// This ensures that mouseClickHandler and mouseMotionHandler are no-ops.
global_mouseInput = nullptr;
// Reset the Pimpl
d.reset();
}
void FGMouseInput::reinit()
{
shutdown();
init();
} }
void FGMouseInput::update ( double dt ) void FGMouseInput::update ( double dt )
@ -522,18 +530,6 @@ mouse_mode::mouse_mode ()
{ {
} }
mouse_mode::~mouse_mode ()
{
// FIXME: memory leak
// for (int i = 0; i < KEYMOD_MAX; i++) {
// int j;
// for (j = 0; i < x_bindings[i].size(); j++)
// delete bindings[i][j];
// for (j = 0; j < y_bindings[i].size(); j++)
// delete bindings[i][j];
// }
}
void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea) void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea)
{ {
if (!d) { if (!d) {

View file

@ -40,10 +40,12 @@ namespace osgGA { class GUIEventAdapter; }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
class FGMouseInput : public SGSubsystem, FGCommonInput { class FGMouseInput : public SGSubsystem, FGCommonInput {
public: public:
FGMouseInput(); FGMouseInput();
virtual ~FGMouseInput(); virtual ~FGMouseInput() = default;
void init() override; void init() override;
void shutdown() override;
void reinit() override;
void update( double dt ) override; void update( double dt ) override;
static const char* subsystemName() { return "input-mouse"; } static const char* subsystemName() { return "input-mouse"; }