1
0
Fork 0

Fixed minor memory leak on joystick reload.

This commit is contained in:
ThorstenB 2011-04-13 21:30:11 +02:00
parent 8513a057f3
commit 1456635c55
2 changed files with 22 additions and 5 deletions

View file

@ -55,10 +55,15 @@ FGJoystickInput::joystick::joystick ()
FGJoystickInput::joystick::~joystick () FGJoystickInput::joystick::~joystick ()
{ {
// delete js? why not? // delete js? no, since js == this - and we're in the destructor already.
// delete js;
delete[] axes; delete[] axes;
delete[] buttons; delete[] buttons;
jsnum = 0;
js = NULL;
naxes = 0;
nbuttons = 0;
axes = NULL;
buttons = NULL;
} }
@ -68,13 +73,24 @@ FGJoystickInput::FGJoystickInput()
FGJoystickInput::~FGJoystickInput() FGJoystickInput::~FGJoystickInput()
{ {
_remove();
} }
void FGJoystickInput::_remove()
{
SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true);
js_nodes->removeChildren("js", false);
for (int i = 0; i < MAX_JOYSTICKS; i++)
{
if (bindings[i].js)
delete bindings[i].js;
bindings[i].js = NULL;
}
}
void FGJoystickInput::init() void FGJoystickInput::init()
{ {
jsInit(); jsInit();
// TODO: zero the old bindings first.
SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings"); SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true); SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true);
@ -121,8 +137,7 @@ void FGJoystickInput::init()
void FGJoystickInput::reinit() { void FGJoystickInput::reinit() {
SG_LOG(SG_INPUT, SG_DEBUG, "Re-Initializing joystick bindings"); SG_LOG(SG_INPUT, SG_DEBUG, "Re-Initializing joystick bindings");
SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true); _remove();
js_nodes->removeChildren("js", false);
FGJoystickInput::init(); FGJoystickInput::init();
FGJoystickInput::postinit(); FGJoystickInput::postinit();
} }

View file

@ -52,6 +52,8 @@ public:
static const int MAX_JOYSTICK_BUTTONS = 32; static const int MAX_JOYSTICK_BUTTONS = 32;
private: private:
void _remove();
/** /**
* Settings for a single joystick axis. * Settings for a single joystick axis.
*/ */