From 9c69fc7bfbd803d813f7539d3617657b2875c927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Wed, 1 Sep 2021 10:32:18 +0200 Subject: [PATCH 1/4] Remove explicit deletion of buttins in destructors. These objects are deleted automatically by parent objects. --- src/inputdaemon.cpp | 24 ------------------------ src/inputdaemon.h | 1 - src/inputdevice.cpp | 18 +----------------- src/joycontrolstick.cpp | 4 ++-- src/main.cpp | 4 ---- src/setjoystick.cpp | 11 +---------- 6 files changed, 4 insertions(+), 58 deletions(-) diff --git a/src/inputdaemon.cpp b/src/inputdaemon.cpp index 27775b8e8..5ea44239d 100644 --- a/src/inputdaemon.cpp +++ b/src/inputdaemon.cpp @@ -291,30 +291,6 @@ void InputDaemon::refreshJoysticks() emit joysticksRefreshed(m_joysticks); } -void InputDaemon::deleteJoysticks() -{ - QMapIterator iter(*m_joysticks); - - while (iter.hasNext()) - { - InputDevice *joystick = iter.next().value(); - - for (auto el : joystick->getJoystick_sets().values()) - { - } - - if (joystick != nullptr) - { - delete joystick; - joystick = nullptr; - } - } - - m_joysticks->clear(); - getTrackjoysticksLocal().clear(); - trackcontrollers.clear(); -} - void InputDaemon::stop() { stopped = true; diff --git a/src/inputdaemon.h b/src/inputdaemon.h index 370c46e37..9871583d9 100644 --- a/src/inputdaemon.h +++ b/src/inputdaemon.h @@ -72,7 +72,6 @@ class InputDaemon : public QObject void refresh(); void refreshJoystick(InputDevice *joystick); void refreshJoysticks(); - void deleteJoysticks(); void startWorker(); void refreshMapping(QString mapping, InputDevice *device); void removeDevice(InputDevice *device); diff --git a/src/inputdevice.cpp b/src/inputdevice.cpp index 52639f1ad..fdd1a3a7c 100644 --- a/src/inputdevice.cpp +++ b/src/inputdevice.cpp @@ -50,23 +50,7 @@ InputDevice::InputDevice(SDL_Joystick *joystick, int deviceIndex, AntiMicroSetti m_settings = settings; } -InputDevice::~InputDevice() -{ - QHashIterator iter(getJoystick_sets()); - - while (iter.hasNext()) - { - SetJoystick *setjoystick = iter.next().value(); - - if (setjoystick != nullptr) - { - getJoystick_sets().remove(iter.key()); - delete setjoystick; - } - } - - getJoystick_sets().clear(); -} +InputDevice::~InputDevice() {} int InputDevice::getJoyNumber() { return joyNumber; } diff --git a/src/joycontrolstick.cpp b/src/joycontrolstick.cpp index be2831f76..573ebb6b2 100644 --- a/src/joycontrolstick.cpp +++ b/src/joycontrolstick.cpp @@ -59,8 +59,6 @@ JoyControlStick::~JoyControlStick() { axisX->removeControlStick(false); axisY->removeControlStick(false); - - deleteButtons(); } /** @@ -915,6 +913,8 @@ void JoyControlStick::refreshButtons() /** * @brief Delete stick direction buttons and stick modifier button. + * + * (Not used by destructor because parents delete children automatically) */ void JoyControlStick::deleteButtons() { diff --git a/src/main.cpp b/src/main.cpp index dfee4305e..df06bbcd5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -522,7 +522,6 @@ int main(int argc, char *argv[]) mainAppHelper.printControllerList(joysticks); joypad_worker->quit(); - joypad_worker->deleteJoysticks(); delete joysticks; joysticks = nullptr; @@ -550,8 +549,6 @@ int main(int argc, char *argv[]) QObject::connect(&antimicrox, &QApplication::aboutToQuit, mainWindow, &MainWindow::removeJoyTabs); QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::quit); - QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::deleteJoysticks, - Qt::BlockingQueuedConnection); QObject::connect(&antimicrox, &QApplication::aboutToQuit, &PadderCommon::mouseHelperObj, &MouseHelper::deleteDeskWid, Qt::DirectConnection); QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::deleteLater, @@ -703,7 +700,6 @@ int main(int argc, char *argv[]) QObject::connect(&antimicrox, &QApplication::aboutToQuit, mainWindow, &MainWindow::removeJoyTabs); QObject::connect(&antimicrox, &QApplication::aboutToQuit, &mainAppHelper, &AppLaunchHelper::revertMouseThread); QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::quit); - QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::deleteJoysticks); QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::deleteLater); QObject::connect(&antimicrox, &QApplication::aboutToQuit, &PadderCommon::mouseHelperObj, &MouseHelper::deleteDeskWid, Qt::DirectConnection); diff --git a/src/setjoystick.cpp b/src/setjoystick.cpp index fe891bab9..3b4a408ac 100644 --- a/src/setjoystick.cpp +++ b/src/setjoystick.cpp @@ -49,16 +49,7 @@ SetJoystick::SetJoystick(InputDevice *device, int index, bool runreset, QObject reset(); } -SetJoystick::~SetJoystick() -{ - deleteSticks(); - deleteVDpads(); - deleteButtons(); - deleteAxes(); - deleteHats(); - - removeAllBtnFromQueue(); -} +SetJoystick::~SetJoystick() { removeAllBtnFromQueue(); } JoyButton *SetJoystick::getJoyButton(int index) const { return getButtons().value(index); } From a8e52d55884ba8b99a86be126b0d0d7845d1db5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Wed, 1 Sep 2021 10:20:38 +0200 Subject: [PATCH 2/4] Use deleteLater for destroying joypad_worker --- src/main.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index df06bbcd5..d8f4a005f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -733,6 +733,11 @@ int main(int argc, char *argv[]) delete localServer; localServer = nullptr; + if (!joypad_worker.isNull()) + { + joypad_worker->deleteLater(); + } + inputEventThread->quit(); inputEventThread->wait(); @@ -759,12 +764,6 @@ int main(int argc, char *argv[]) delete mainWindow; mainWindow = nullptr; - if (!joypad_worker.isNull()) - { - delete joypad_worker; - joypad_worker.clear(); - } - delete appLogger; return app_result; } From 20798437e7f9e277feccb9400ec638122c6aca7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Wed, 1 Sep 2021 10:21:55 +0200 Subject: [PATCH 3/4] Remove default parent value from constructors to encourage to setting parents of objects --- src/gamecontroller/gamecontroller.h | 2 +- src/inputdevice.h | 2 +- src/joyaxis.h | 2 +- src/joybutton.h | 2 +- src/joybuttontypes/joycontrolstickbutton.h | 4 ++-- src/joybuttontypes/joycontrolstickmodifierbutton.h | 3 +-- src/joycontrolstick.h | 2 +- src/joydpad.h | 2 +- src/joystick.h | 2 +- src/setjoystick.h | 4 ++-- src/vdpad.h | 4 ++-- 11 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/gamecontroller/gamecontroller.h b/src/gamecontroller/gamecontroller.h index a42573da4..f9e576baf 100644 --- a/src/gamecontroller/gamecontroller.h +++ b/src/gamecontroller/gamecontroller.h @@ -34,7 +34,7 @@ class GameController : public InputDevice public: explicit GameController(SDL_GameController *controller, int deviceIndex, AntiMicroSettings *settings, int counterUniques, - QObject *parent = nullptr); + QObject *parent); virtual QString getName() override; virtual QString getSDLName() override; diff --git a/src/inputdevice.h b/src/inputdevice.h index c382395ed..9813b1f01 100644 --- a/src/inputdevice.h +++ b/src/inputdevice.h @@ -34,7 +34,7 @@ class InputDevice : public QObject Q_OBJECT public: - explicit InputDevice(SDL_Joystick *joystick, int deviceIndex, AntiMicroSettings *settings, QObject *parent = nullptr); + explicit InputDevice(SDL_Joystick *joystick, int deviceIndex, AntiMicroSettings *settings, QObject *parent); virtual ~InputDevice(); virtual int getNumberButtons(); diff --git a/src/joyaxis.h b/src/joyaxis.h index 59f0f7275..17bbe5665 100644 --- a/src/joyaxis.h +++ b/src/joyaxis.h @@ -36,7 +36,7 @@ class JoyAxis : public QObject Q_OBJECT public: - explicit JoyAxis(int index, int originset, SetJoystick *parentSet, QObject *parent = 0); + explicit JoyAxis(int index, int originset, SetJoystick *parentSet, QObject *parent); ~JoyAxis(); enum ThrottleTypes diff --git a/src/joybutton.h b/src/joybutton.h index 492df8b41..722b41482 100644 --- a/src/joybutton.h +++ b/src/joybutton.h @@ -43,7 +43,7 @@ class JoyButton : public QObject Q_OBJECT public: - explicit JoyButton(int index, int originset, SetJoystick *parentSet, QObject *parent = 0); + explicit JoyButton(int index, int originset, SetJoystick *parentSet, QObject *parent); ~JoyButton(); enum SetChangeCondition diff --git a/src/joybuttontypes/joycontrolstickbutton.h b/src/joybuttontypes/joycontrolstickbutton.h index be52218fc..cb19e806e 100644 --- a/src/joybuttontypes/joycontrolstickbutton.h +++ b/src/joybuttontypes/joycontrolstickbutton.h @@ -31,9 +31,9 @@ class JoyControlStickButton : public JoyGradientButton public: explicit JoyControlStickButton(JoyControlStick *stick, int index, int originset, SetJoystick *parentSet, - QObject *parent = nullptr); + QObject *parent); explicit JoyControlStickButton(JoyControlStick *stick, JoyStickDirectionsType::JoyStickDirections index, int originset, - SetJoystick *parentSet, QObject *parent = nullptr); + SetJoystick *parentSet, QObject *parent); virtual int getRealJoyNumber() const; virtual QString getPartialName(bool forceFullFormat = false, bool displayNames = false) const; diff --git a/src/joybuttontypes/joycontrolstickmodifierbutton.h b/src/joybuttontypes/joycontrolstickmodifierbutton.h index b5ca33c7b..f7f3b3d96 100644 --- a/src/joybuttontypes/joycontrolstickmodifierbutton.h +++ b/src/joybuttontypes/joycontrolstickmodifierbutton.h @@ -29,8 +29,7 @@ class JoyControlStickModifierButton : public JoyGradientButton Q_OBJECT public: - explicit JoyControlStickModifierButton(JoyControlStick *stick, int originset, SetJoystick *parentSet, - QObject *parent = nullptr); + explicit JoyControlStickModifierButton(JoyControlStick *stick, int originset, SetJoystick *parentSet, QObject *parent); virtual QString getPartialName(bool forceFullFormat = false, bool displayNames = false) const; virtual QString getXmlName(); diff --git a/src/joycontrolstick.h b/src/joycontrolstick.h index 0fb8c2101..8f02d942b 100644 --- a/src/joycontrolstick.h +++ b/src/joycontrolstick.h @@ -33,7 +33,7 @@ class JoyControlStick : public QObject, public JoyStickDirectionsType Q_OBJECT public: - explicit JoyControlStick(JoyAxis *axisX, JoyAxis *axisY, int index, int originset = 0, QObject *parent = nullptr); + explicit JoyControlStick(JoyAxis *axisX, JoyAxis *axisY, int index, int originset, QObject *parent); ~JoyControlStick(); enum JoyMode diff --git a/src/joydpad.h b/src/joydpad.h index adba68779..66197237b 100644 --- a/src/joydpad.h +++ b/src/joydpad.h @@ -26,7 +26,7 @@ class JoyDPad : public QObject Q_OBJECT public: - explicit JoyDPad(int index, int originset, SetJoystick *parentSet, QObject *parent = 0); + explicit JoyDPad(int index, int originset, SetJoystick *parentSet, QObject *parent); ~JoyDPad(); enum JoyMode diff --git a/src/joystick.h b/src/joystick.h index d4abfbeba..89ce84dd2 100644 --- a/src/joystick.h +++ b/src/joystick.h @@ -30,7 +30,7 @@ class Joystick : public InputDevice Q_OBJECT public: - explicit Joystick(SDL_Joystick *joyhandle, int deviceIndex, AntiMicroSettings *settings, QObject *parent = 0); + explicit Joystick(SDL_Joystick *joyhandle, int deviceIndex, AntiMicroSettings *settings, QObject *parent); virtual QString getName() override; virtual QString getSDLName() override; diff --git a/src/setjoystick.h b/src/setjoystick.h index 32d2dd6a1..11c30fc72 100644 --- a/src/setjoystick.h +++ b/src/setjoystick.h @@ -33,8 +33,8 @@ class SetJoystick : public SetJoystickXml Q_OBJECT public: - explicit SetJoystick(InputDevice *device, int index, QObject *parent = 0); - explicit SetJoystick(InputDevice *device, int index, bool runreset, QObject *parent = 0); + explicit SetJoystick(InputDevice *device, int index, QObject *parent); + explicit SetJoystick(InputDevice *device, int index, bool runreset, QObject *parent); ~SetJoystick(); JoyAxis *getJoyAxis(int index) const; diff --git a/src/vdpad.h b/src/vdpad.h index 9078685fc..0fbdca8cf 100644 --- a/src/vdpad.h +++ b/src/vdpad.h @@ -26,9 +26,9 @@ class VDPad : public JoyDPad Q_OBJECT public: - explicit VDPad(int index, int originset, SetJoystick *parentSet, QObject *parent = nullptr); + explicit VDPad(int index, int originset, SetJoystick *parentSet, QObject *parent); explicit VDPad(JoyButton *upButton, JoyButton *downButton, JoyButton *leftButton, JoyButton *rightButton, int index, - int originset, SetJoystick *parentSet, QObject *parent = nullptr); + int originset, SetJoystick *parentSet, QObject *parent); ~VDPad(); void joyEvent(bool pressed, bool ignoresets = false); From 43706fd4797928cde726bf63e2436dc10983dc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Tue, 31 Aug 2021 23:04:06 +0200 Subject: [PATCH 4/4] Send signal only to existing objects --- src/vdpad.cpp | 8 ++++---- src/vdpad.h | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/vdpad.cpp b/src/vdpad.cpp index 71dd82fcb..affd356cd 100644 --- a/src/vdpad.cpp +++ b/src/vdpad.cpp @@ -54,25 +54,25 @@ VDPad::VDPad(JoyButton *upButton, JoyButton *downButton, JoyButton *leftButton, VDPad::~VDPad() { - if (upButton != nullptr) + if (!upButton.isNull()) { upButton->removeVDPad(); upButton = nullptr; } - if (downButton != nullptr) + if (!downButton.isNull()) { downButton->removeVDPad(); downButton = nullptr; } - if (leftButton != nullptr) + if (!leftButton.isNull()) { leftButton->removeVDPad(); leftButton = nullptr; } - if (rightButton != nullptr) + if (!rightButton.isNull()) { rightButton->removeVDPad(); rightButton = nullptr; diff --git a/src/vdpad.h b/src/vdpad.h index 0fbdca8cf..f6ef914c0 100644 --- a/src/vdpad.h +++ b/src/vdpad.h @@ -21,6 +21,8 @@ #include "joydpad.h" +#include + class VDPad : public JoyDPad { Q_OBJECT @@ -54,10 +56,10 @@ class VDPad : public JoyDPad void activatePendingEvent(); private: - JoyButton *upButton; - JoyButton *downButton; - JoyButton *leftButton; - JoyButton *rightButton; + QPointer upButton; + QPointer downButton; + QPointer leftButton; + QPointer rightButton; bool pendingVDPadEvent; };