Skip to content

Commit a31f16f

Browse files
committed
[Issue No.65] AddJoystick & RemoveJoystick crash or Joysticklist display error issue fix.
Signed-off-by: Melvin Li <kkkwing15@163.com>
1 parent be427a2 commit a31f16f

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

QKeyMapper/QJoysticks/src/QJoysticks/SDL_Joysticks.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ void SDL_Joysticks::update()
147147
configureJoystick(&event);
148148
break;
149149
case SDL_JOYDEVICEREMOVED: {
150-
const QJoystickDevice joystick_removed = *m_joysticks[event.jdevice.which];
151-
emit joystickRemoved(joystick_removed);
150+
if (m_joysticks.contains(event.jdevice.which)
151+
&& m_joysticks[event.jdevice.which] != nullptr) {
152+
const QJoystickDevice joystick_removed = *m_joysticks[event.jdevice.which];
153+
emit joystickRemoved(joystick_removed);
154+
}
152155

153156
SDL_Joystick *js = SDL_JoystickFromInstanceID(event.jdevice.which);
154157
if (js)
@@ -162,11 +165,16 @@ void SDL_Joysticks::update()
162165
SDL_GameControllerClose(gc);
163166
}
164167

165-
delete m_joysticks[event.jdevice.which];
166-
m_joysticks.remove(event.jdevice.which);
168+
if (m_joysticks.contains(event.jdevice.which))
169+
{
170+
if (m_joysticks[event.jdevice.which] != nullptr) {
171+
delete m_joysticks[event.jdevice.which];
172+
}
173+
m_joysticks.remove(event.jdevice.which);
174+
}
167175

168176
emit countChanged();
169-
}
177+
}
170178
break;
171179
case SDL_JOYAXISMOTION:
172180
if (!SDL_IsGameController(event.cdevice.which))

QKeyMapper/QKeyMapper.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ IDI_ICON1 ICON "image/QKeyMapper.ico"
99

1010
// Version
1111
VS_VERSION_INFO VERSIONINFO
12-
FILEVERSION 1,3,6,0
13-
PRODUCTVERSION 1,3,6,0
12+
FILEVERSION 1,3,7,0
13+
PRODUCTVERSION 1,3,7,0
1414
FILEFLAGSMASK 0x17L
1515
#ifdef _DEBUG
1616
FILEFLAGS 0x1L

QKeyMapper/qkeymapper_worker.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,7 +5262,8 @@ void QKeyMapper_Worker::onJoystickAdded(QJoystickDevice *joystick_added)
52625262
#ifdef DEBUG_LOGOUT_ON
52635263
QString vendorIdStr = QString("0x%1").arg(QString::number(joystick_added->vendorid, 16).toUpper(), 4, '0');
52645264
QString productIdStr = QString("0x%1").arg(QString::number(joystick_added->productid, 16).toUpper(), 4, '0');
5265-
qDebug().nospace() << "[onJoystickAdded] Added a New Gamepad -> " << "Name = " << joystick_added->name << ", PlayerIndex = " << joystick_added->playerindex << ", ID = " << joystick_added->id << ", VendorID = " << vendorIdStr << ", ProductID = " << productIdStr << ", ButtonNumbers = " << joystick_added->numbuttons << ", Serial = " << joystick_added->serial;
5265+
QString debugmessage = QString("[onJoystickAdded] Added a New Gamepad -> Name=\"%1\", PlayerIndex=%2, ID=%3, VendorID=%4, ProductID=%5, ButtonNumbers=%6, Serial=%7").arg(joystick_added->name).arg(joystick_added->playerindex).arg(joystick_added->id).arg(vendorIdStr, productIdStr).arg(joystick_added->numbuttons).arg(joystick_added->serial);
5266+
qDebug().nospace().noquote() << debugmessage;
52665267
#endif
52675268

52685269
if (joystick_added == Q_NULLPTR) {
@@ -5286,7 +5287,8 @@ void QKeyMapper_Worker::onJoystickAdded(QJoystickDevice *joystick_added)
52865287
if (virtualgamepad) {
52875288
joystick_added->blacklisted = true;
52885289
#ifdef DEBUG_LOGOUT_ON
5289-
qDebug().noquote().nospace() << "[onJoystickAdded] VirtualGamdpad[" << joystick_added->name << "] PlayerIndex = " << joystick_added->playerindex << ", ID = " << joystick_added->id << ", VendorID = " << vendorIdStr << ", ProductID = " << productIdStr << ", is Blacklisted!";
5290+
QString debugmessage = QString("[onJoystickAdded] VirtualGamdpad[%1] PlayerIndex=%2, ID=%3, VendorID=%4, ProductID=%5, is Blacklisted!").arg(joystick_added->name).arg(joystick_added->playerindex).arg(joystick_added->id).arg(vendorIdStr, productIdStr);
5291+
qDebug().nospace().noquote() << debugmessage;
52905292
#endif
52915293
}
52925294

@@ -5299,7 +5301,8 @@ void QKeyMapper_Worker::onJoystickRemoved(const QJoystickDevice joystick_removed
52995301
#ifdef DEBUG_LOGOUT_ON
53005302
QString vendorIdStr = QString("0x%1").arg(QString::number(joystick_removed.vendorid, 16).toUpper(), 4, '0');
53015303
QString productIdStr = QString("0x%1").arg(QString::number(joystick_removed.productid, 16).toUpper(), 4, '0');
5302-
qDebug().nospace() << "[onJoystickRemoved] Removed a Gamepad -> " << "Name = " << joystick_removed.name << ", PlayerIndex = " << joystick_removed.playerindex << ", ID = " << joystick_removed.id << ", VendorID = " << vendorIdStr << ", ProductID = " << productIdStr << ", ButtonNumbers = " << joystick_removed.numbuttons << ", Serial = " << joystick_removed.serial;
5304+
QString debugmessage = QString("[onJoystickRemoved] Removed a Gamepad -> Name=\"%1\", PlayerIndex=%2, ID=%3, VendorID=%4, ProductID=%5, ButtonNumbers=%6, Serial=%7").arg(joystick_removed.name).arg(joystick_removed.playerindex).arg(joystick_removed.id).arg(vendorIdStr, productIdStr).arg(joystick_removed.numbuttons).arg(joystick_removed.serial);
5305+
qDebug().nospace().noquote() << debugmessage;
53035306
#endif
53045307

53055308
emit QKeyMapper::getInstance()->updateGamepadSelectComboBox_Signal();

0 commit comments

Comments
 (0)