1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-21 07:15:12 +03:00

Re #1732: stack corruption fixed (ported from master)

This commit is contained in:
Damjan Adamic 2015-07-02 19:35:35 +02:00
parent 07ac7db085
commit d73f3ed19a

View file

@ -115,23 +115,26 @@ void joystickDialog::on_cancelButton_clicked() {
this->close(); this->close();
} }
void joystickDialog::on_okButton_clicked() { void joystickDialog::on_okButton_clicked()
int sticks[8]={0,0,0,0,0,0,0,0}; {
int stickAssignments[MAX_JOYSTICKS] = {0};
foreach(QComboBox *cb, findChildren<QComboBox *>(QRegExp("jsmapCB_[0-9]+"))) { foreach(QComboBox *cb, findChildren<QComboBox *>(QRegExp("jsmapCB_[0-9]+"))) {
sticks[cb->currentIndex()]++; int mappedValue = cb->currentIndex() - 1;
} // qDebug() << "cb->currentIndex()" << mappedValue;
bool duplicated=false; if (mappedValue >= 0 && mappedValue < MAX_JOYSTICKS) {
for (int i=1; i<8;i++) { stickAssignments[mappedValue]++;
if (sticks[i]>1) {
duplicated=true;
} }
} }
if (duplicated) {
QMessageBox::critical(this, tr("Error"), tr("Duplicated stick assignement")); for (int i=0; i<MAX_JOYSTICKS; i++) {
return; if (stickAssignments[i] > 1) {
QMessageBox::critical(this, tr("Error"), tr("Duplicated stick assignment"));
return;
}
} }
joystick->close(); joystick->close();
for (int i=0; i<8;i++) { for (int i=0; i<MAX_JOYSTICKS; i++) {
g.joystick[i].remove(); g.joystick[i].remove();
} }
QCheckBox * ib[]={ui->ChInv_1, ui->ChInv_2, ui->ChInv_3, ui->ChInv_4, ui->ChInv_5, ui->ChInv_6, ui->ChInv_7, ui->ChInv_8}; QCheckBox * ib[]={ui->ChInv_1, ui->ChInv_2, ui->ChInv_3, ui->ChInv_4, ui->ChInv_5, ui->ChInv_6, ui->ChInv_7, ui->ChInv_8};
@ -139,7 +142,7 @@ void joystickDialog::on_okButton_clicked() {
int axe=cb->objectName().mid(cb->objectName().lastIndexOf("_")+1).toInt()-1; int axe=cb->objectName().mid(cb->objectName().lastIndexOf("_")+1).toInt()-1;
int stick=cb->currentIndex() - 1; int stick=cb->currentIndex() - 1;
qDebug() << "joystick mapping " << cb->objectName() <<"axe:" << axe << "stick:" << stick; qDebug() << "joystick mapping " << cb->objectName() <<"axe:" << axe << "stick:" << stick;
if (stick >= 0) { if (stick >= 0 && stick < MAX_JOYSTICKS) {
g.joystick[stick].stick_axe( axe ); g.joystick[stick].stick_axe( axe );
g.joystick[stick].stick_max( jscal[axe][2] ); g.joystick[stick].stick_max( jscal[axe][2] );
g.joystick[stick].stick_med( jscal[axe][1] ); g.joystick[stick].stick_med( jscal[axe][1] );