From e9ffd980f06e0211eab31e98126566a2d5a549dc Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 18 Dec 2005 21:24:33 +0000 Subject: [PATCH] fix stale INPUTMAN pointer in Lua after device change --- stepmania/src/GameLoop.cpp | 3 +-- stepmania/src/RageInput.cpp | 21 ++++++++++++++++----- stepmania/src/RageInput.h | 2 ++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/stepmania/src/GameLoop.cpp b/stepmania/src/GameLoop.cpp index 6f22bac359..65336e94dd 100644 --- a/stepmania/src/GameLoop.cpp +++ b/stepmania/src/GameLoop.cpp @@ -100,8 +100,7 @@ void GameLoop() if( INPUTMAN->DevicesChanged() ) { - SAFE_DELETE( INPUTMAN ); - INPUTMAN = new RageInput( PREFSMAN->GetInputDrivers() ); + INPUTMAN->LoadDrivers(); StepMania::CheckForChangedInputDevicesAndRemap(); } diff --git a/stepmania/src/RageInput.cpp b/stepmania/src/RageInput.cpp index f471b760bc..dacd592def 100644 --- a/stepmania/src/RageInput.cpp +++ b/stepmania/src/RageInput.cpp @@ -12,12 +12,9 @@ RageInput::RageInput( CString sDriverList ) { LOG->Trace( "RageInput::RageInput()" ); - /* Init optional devices. */ - MakeInputHandlers( sDriverList, m_pDevices ); + m_sDriverList = sDriverList; - /* If no input devices are loaded, the user won't be able to input anything. */ - if( m_pDevices.size() == 0 ) - LOG->Warn( "No input devices were loaded." ); + LoadDrivers(); } RageInput::~RageInput() @@ -27,6 +24,20 @@ RageInput::~RageInput() delete m_pDevices[i]; } +void RageInput::LoadDrivers() +{ + for( unsigned i = 0; i < m_pDevices.size(); ++i ) + delete m_pDevices[i]; + m_pDevices.clear(); + + /* Init optional devices. */ + MakeInputHandlers( m_sDriverList, m_pDevices ); + + /* If no input devices are loaded, the user won't be able to input anything. */ + if( m_pDevices.size() == 0 ) + LOG->Warn( "No input devices were loaded." ); +} + void RageInput::Update( float fDeltaTime ) { /* Update optional devices. */ diff --git a/stepmania/src/RageInput.h b/stepmania/src/RageInput.h index 6a06fd8038..0657fd34cd 100644 --- a/stepmania/src/RageInput.h +++ b/stepmania/src/RageInput.h @@ -14,6 +14,7 @@ public: RageInput( CString sDriverList ); ~RageInput(); + void LoadDrivers(); void Update( float fDeltaTime ); bool DevicesChanged(); void GetDevicesAndDescriptions( vector& vDevicesOut, vector& vsDescriptionsOut ); @@ -27,6 +28,7 @@ public: private: vector m_pDevices; + CString m_sDriverList; }; extern RageInput* INPUTMAN; // global and accessable from anywhere in our program