summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-02-18 15:50:43 +0300
committerAndrei Karas <akaras@inbox.ru>2016-02-18 15:55:22 +0300
commit571d6151f0983e488feafb3cd6c9c74bbd038082 (patch)
treec5f410e872d0a33b7efa8157fff3b92346192a0a /src
parent02cc3470578d1c950cbd7731f86e24167d04a9df (diff)
downloadplus-571d6151f0983e488feafb3cd6c9c74bbd038082.tar.gz
plus-571d6151f0983e488feafb3cd6c9c74bbd038082.tar.bz2
plus-571d6151f0983e488feafb3cd6c9c74bbd038082.tar.xz
plus-571d6151f0983e488feafb3cd6c9c74bbd038082.zip
Add some extra checks and logging while sorting keys.
Diffstat (limited to 'src')
-rw-r--r--src/input/inputactionsortfunctor.h17
-rw-r--r--src/input/inputmanager.cpp21
2 files changed, 35 insertions, 3 deletions
diff --git a/src/input/inputactionsortfunctor.h b/src/input/inputactionsortfunctor.h
index 6a3a72245..6884f9c11 100644
--- a/src/input/inputactionsortfunctor.h
+++ b/src/input/inputactionsortfunctor.h
@@ -21,6 +21,8 @@
#ifndef INPUT_INPUTACTIONSORTFUNCTOR_H
#define INPUT_INPUTACTIONSORTFUNCTOR_H
+#include "logger.h"
+
#include "input/inputactiondata.h"
#include "localconsts.h"
@@ -31,8 +33,19 @@ class InputActionSortFunctor final
bool operator() (const InputActionT key1,
const InputActionT key2) const
{
- return keys[CAST_SIZE(key1)].priority
- >= keys[CAST_SIZE(key2)].priority;
+ const size_t k1 = CAST_SIZE(key1);
+ const size_t k2 = CAST_SIZE(key2);
+ if (k1 >= CAST_SIZE(InputAction::TOTAL))
+ {
+ logger->log("broken key1: %ld", static_cast<long>(k1));
+ return false;
+ }
+ if (k2 >= CAST_SIZE(InputAction::TOTAL))
+ {
+ logger->log("broken key2: %ld", static_cast<long>(k2));
+ return false;
+ }
+ return keys[k1].priority >= keys[k2].priority;
}
const InputActionData *keys A_NONNULLPOINTER;
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index 4f9c1ce6b..eb6627d2a 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -921,8 +921,27 @@ void InputManager::updateKeyActionMap(KeyToActionMap &restrict actionMap,
FOR_EACH (KeyToActionMapIter, it, actionMap)
{
KeysVector *const keys = &it->second;
- if (keys && keys->size() > 1)
+ if (!keys)
+ continue;
+ const size_t sz = keys->size();
+ if (sz > 1)
+ {
+ logger->log("keys size: %d", CAST_S32(sz));
+ int sum = 0;
+ FOR_EACHP (KeysVectorIter, itk, keys)
+ {
+ const size_t val = CAST_SIZE(*itk);
+ if (val >= CAST_SIZE(InputAction::TOTAL))
+ {
+ logger->log("wrong action index: %ld",
+ static_cast<long>(val));
+ break;
+ }
+ sum += inputActionData[val].priority;
+ }
+ logger->log("sum: %d", sum);
std::sort(keys->begin(), keys->end(), inputActionDataSorter);
+ }
}
}