From 69a56e867749944dc0e86b9ef5c54bac4339b454 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Fri, 16 Jul 2010 14:54:41 +0200 Subject: [PATCH] Added more safety asserts to input dispatcher --- input/dispatcher.hpp | 13 +++++++++++-- input/func_binder.hpp | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/input/dispatcher.hpp b/input/dispatcher.hpp index 930195856a..dd6fb6bf6d 100644 --- a/input/dispatcher.hpp +++ b/input/dispatcher.hpp @@ -4,6 +4,7 @@ #include "dispatch_map.hpp" #include "func_binder.hpp" #include +#include namespace OEngine { namespace Input { @@ -19,8 +20,16 @@ struct Dispatcher : Mangle::Input::Event */ Dispatcher(int actions) : funcs(actions) {} - void bind(int action, int key) { map.bind(key, action); } - void unbind(int action, int key) { map.unbind(key, action); } + void bind(unsigned int action, int key) + { + assert(action < funcs.getSize()); + map.bind(key, action); + } + void unbind(unsigned int action, int key) + { + assert(action < funcs.getSize()); + map.unbind(key, action); + } bool isBound(int key) const { return map.isBound(key); } /** diff --git a/input/func_binder.hpp b/input/func_binder.hpp index d2bfd53e5b..7aa733edf8 100644 --- a/input/func_binder.hpp +++ b/input/func_binder.hpp @@ -50,6 +50,8 @@ public: */ FuncBinder(int number) : bindings(number) {} + unsigned int getSize() { return bindings.size(); } + /** Bind an action to an index. */