From e2b34f1ee90987f7caefb45eb18e7dac9d61fff1 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 26 Dec 2009 10:21:50 +0000 Subject: [PATCH] Don't register already registered listeners --- virtual_keyboard.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/virtual_keyboard.cpp b/virtual_keyboard.cpp index 55f1614..cd67212 100644 --- a/virtual_keyboard.cpp +++ b/virtual_keyboard.cpp @@ -225,11 +225,15 @@ void VirtualKeyboard::registerListener(KeyboardListener *kl) int n_listeners = sizeof(this->listeners) / sizeof(*this->listeners); int i; + /* Don't register already registered listeners */ + for (i = 0; i < n_listeners; i++) + if (this->listeners[i] == kl) + return; + /* Find a free spot */ for (i = 0; i < n_listeners; i++) - { if (!this->listeners[i]) break; - } + panic_if(i == n_listeners, "No free listeners!\n"); this->listeners[i] = kl; @@ -334,9 +338,9 @@ void VirtualKeyboard::flushListeners() void VirtualKeyboard::deactivate() { - this->is_active = false; - this->flushListeners(); - Gui::gui->popView(); + this->is_active = false; + this->flushListeners(); + Gui::gui->popView(); } void VirtualKeyboard::draw(SDL_Surface *where)