From 2ec41e6c83173d6f4267f9d444c512299eec91b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Panzenb=C3=B6ck?= Date: Sun, 3 Apr 2016 01:17:15 +0200 Subject: [PATCH] fix segfault b/c QList is now used instead of QHash --- src/joypad.cpp | 8 ++++---- src/quickset.cpp | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/joypad.cpp b/src/joypad.cpp index b9f72d5..56d05f0 100644 --- a/src/joypad.cpp +++ b/src/joypad.cpp @@ -152,8 +152,8 @@ bool JoyPad::readConfig( QTextStream &stream ) { errorBox(tr("Layout file error"), tr("Expected ':', found '%1'.").arg(ch)); return false; } - if (buttons[num-1] == 0) { - buttons.insert(num-1,new Button(num-1,this)); + for (int i = buttons.size(); i < num; ++ i) { + buttons.append(new Button(i, this)); } if (!buttons[num-1]->read( stream )) { errorBox(tr("Layout file error"), tr("Error reading Button %1").arg(num)); @@ -172,8 +172,8 @@ bool JoyPad::readConfig( QTextStream &stream ) { errorBox(tr("Layout file error"), tr("Expected ':', found '%1'.").arg(ch)); return false; } - if (axes[num-1] == 0) { - axes.insert(num-1,new Axis(num-1,this)); + for (int i = axes.size(); i < num; ++ i) { + axes.append(new Axis(i, this)); } if (!axes[num-1]->read(stream)) { errorBox(tr("Layout file error"), tr("Error reading Axis %1").arg(num)); diff --git a/src/quickset.cpp b/src/quickset.cpp index a4daa13..f3e9d23 100644 --- a/src/quickset.cpp +++ b/src/quickset.cpp @@ -25,9 +25,8 @@ void QuickSet::jsevent(const js_event &msg ) { unsigned int type = msg.type & ~JS_EVENT_INIT; if (type == JS_EVENT_BUTTON) { //capture that button. - Button* button = joypad->buttons[msg.number]; - - if (button) { + if (msg.number < joypad->buttons.size()) { + Button* button = joypad->buttons[msg.number]; //go into setting mode and request a key/mousebutton setting = true; bool isMouse = false; @@ -44,17 +43,19 @@ void QuickSet::jsevent(const js_event &msg ) { if (abs(msg.value) < 5000) return; //capture the axis that moved - Axis* axis = joypad->axes[msg.number]; + if (msg.number < joypad->axes.size()) { + Axis* axis = joypad->axes[msg.number]; - //grab a keycode for that axis and that direction - setting = true; - bool isMouse = false; - int code = KeyDialog::getKey((msg.value >= 0 ? tr("%1, positive") : tr("%1, negative")).arg(axis->getName()), true, &isMouse, this); - setting = false; + //grab a keycode for that axis and that direction + setting = true; + bool isMouse = false; + int code = KeyDialog::getKey((msg.value >= 0 ? tr("%1, positive") : tr("%1, negative")).arg(axis->getName()), true, &isMouse, this); + setting = false; - //assign the key to the axis. - if (code >= 0) { - axis->setKey(isMouse, (msg.value > 0), code); + //assign the key to the axis. + if (code >= 0) { + axis->setKey(isMouse, (msg.value > 0), code); + } } } }