From 42381d33a40d81d58e4d934ac8f247859a73a8db Mon Sep 17 00:00:00 2001 From: Benlitz Date: Wed, 31 Jul 2013 13:54:15 +0000 Subject: [PATCH] fixed a crash when updating a binding that has been bound to an unexisting key/axis of an existing device --- src/input/controller.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/input/controller.h b/src/input/controller.h index 37baa190..cece1542 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -30,8 +30,10 @@ public: void Bind(const char* device_name, const char* key_name); + bool IsBound() { return m_device && m_keyindex != -1; } + protected: - void Update() { m_previous = m_current; m_current = m_device ? m_device->GetKey(m_keyindex) : false; } + void Update() { m_previous = m_current; m_current = IsBound() ? m_device->GetKey(m_keyindex) : false; } const InputDevice* m_device; int m_keyindex; @@ -51,8 +53,10 @@ public: void Bind(const char* device_name, const char* axis_name); + bool IsBound() { return m_device && m_axisindex != -1; } + protected: - void Update() { m_previous = m_current; m_current = m_device ? m_device->GetAxis(m_axisindex) : 0.0f; } + void Update() { m_previous = m_current; m_current = IsBound() ? m_device->GetAxis(m_axisindex) : 0.0f; } const InputDevice* m_device; int m_axisindex;