Skip to content

Commit

Permalink
fix: Class destruction fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pktiuk authored Sep 1, 2021
2 parents 7a98ab2 + 43706fd commit ad2ddd8
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/gamecontroller/gamecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 0 additions & 24 deletions src/inputdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,30 +291,6 @@ void InputDaemon::refreshJoysticks()
emit joysticksRefreshed(m_joysticks);
}

void InputDaemon::deleteJoysticks()
{
QMapIterator<SDL_JoystickID, InputDevice *> 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;
Expand Down
1 change: 0 additions & 1 deletion src/inputdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 1 addition & 17 deletions src/inputdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,7 @@ InputDevice::InputDevice(SDL_Joystick *joystick, int deviceIndex, AntiMicroSetti
m_settings = settings;
}

InputDevice::~InputDevice()
{
QHashIterator<int, SetJoystick *> 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; }

Expand Down
2 changes: 1 addition & 1 deletion src/inputdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/joyaxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/joybutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/joybuttontypes/joycontrolstickbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/joybuttontypes/joycontrolstickmodifierbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/joycontrolstick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ JoyControlStick::~JoyControlStick()
{
axisX->removeControlStick(false);
axisY->removeControlStick(false);

deleteButtons();
}

/**
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/joycontrolstick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/joydpad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 5 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ int main(int argc, char *argv[])
mainAppHelper.printControllerList(joysticks);

joypad_worker->quit();
joypad_worker->deleteJoysticks();

delete joysticks;
joysticks = nullptr;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -737,6 +733,11 @@ int main(int argc, char *argv[])
delete localServer;
localServer = nullptr;

if (!joypad_worker.isNull())
{
joypad_worker->deleteLater();
}

inputEventThread->quit();
inputEventThread->wait();

Expand All @@ -763,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;
}
11 changes: 1 addition & 10 deletions src/setjoystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
4 changes: 2 additions & 2 deletions src/setjoystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/vdpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions src/vdpad.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@

#include "joydpad.h"

#include <QPointer>

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);
Expand All @@ -54,10 +56,10 @@ class VDPad : public JoyDPad
void activatePendingEvent();

private:
JoyButton *upButton;
JoyButton *downButton;
JoyButton *leftButton;
JoyButton *rightButton;
QPointer<JoyButton> upButton;
QPointer<JoyButton> downButton;
QPointer<JoyButton> leftButton;
QPointer<JoyButton> rightButton;
bool pendingVDPadEvent;
};

Expand Down

0 comments on commit ad2ddd8

Please sign in to comment.