Ver código fonte

input: fix a memory leak in the controller code.

undefined
Sam Hocevar 11 anos atrás
pai
commit
e16416a6ee
2 arquivos alterados com 8 adições e 16 exclusões
  1. +4
    -10
      src/input/controller.cpp
  2. +4
    -6
      src/input/controller.h

+ 4
- 10
src/input/controller.cpp Ver arquivo

@@ -68,10 +68,8 @@ Array<Controller*> Controller::controllers;
Controller::Controller(int nb_keys, int nb_axis)
{
m_gamegroup = GAMEGROUP_BEFORE;
m_nb_keys = nb_keys;
m_nb_axis = nb_axis;
m_keys = new KeyBinding[m_nb_keys];
m_axis = new AxisBinding[m_nb_axis];
m_keys.Resize(nb_keys);
m_axis.Resize(nb_axis);
m_activate_nextframe = false;
m_deactivate_nextframe = false;
m_active = false;
@@ -94,15 +92,11 @@ void Controller::TickGame(float seconds)
{
Entity::TickGame(seconds);

for (int i = 0; i < m_nb_keys; ++i)
{
for (int i = 0; i < m_keys.Count(); ++i)
m_keys[i].Update();
}

for (int i = 0; i < m_nb_axis; ++i)
{
for (int i = 0; i < m_axis.Count(); ++i)
m_axis[i].Update();
}

if (m_activate_nextframe)
m_active = true;


+ 4
- 6
src/input/controller.h Ver arquivo

@@ -82,14 +82,12 @@ public:
/** Deactivate every active controller on next frame and return an array of deactivated (previously active) controllers */
static Array<Controller*> DeactivateAll();

KeyBinding& GetKey(int index) { ASSERT(index >= 0 && index < m_nb_keys); return m_keys[index]; }
AxisBinding& GetAxis(int index) { ASSERT(index >= 0 && index < m_nb_axis); return m_axis[index]; }
KeyBinding& GetKey(int index) { return m_keys[index]; }
AxisBinding& GetAxis(int index) { return m_axis[index]; }

protected:
KeyBinding* m_keys;
AxisBinding* m_axis;
int m_nb_keys;
int m_nb_axis;
Array<KeyBinding> m_keys;
Array<AxisBinding> m_axis;

private:
static Array<Controller*> controllers;


Carregando…
Cancelar
Salvar