Skip to content

Commit

Permalink
[Simulator] Fix crash if error happens at startup before timer was cr…
Browse files Browse the repository at this point in the history
…eated.
  • Loading branch information
mpaperno committed Feb 12, 2017
1 parent 5865679 commit d90b1e0
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions companion/src/simulation/simulatorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SimulatorWidget::SimulatorWidget(QWidget * parent, SimulatorInterface *simulator
simulator(simulator),
firmware(getCurrentFirmware()),
radioSettings(GeneralSettings()),
timer(NULL),
timer(new QTimer(this)),
radioUiWidget(NULL),
vJoyLeft(NULL),
vJoyRight(NULL),
Expand Down Expand Up @@ -118,6 +118,10 @@ SimulatorWidget::SimulatorWidget(QWidget * parent, SimulatorInterface *simulator
connect(vJoyRight, SIGNAL(trimButtonPressed(int)), this, SLOT(onTrimPressed(int)));
connect(vJoyRight, SIGNAL(trimButtonReleased()), this, SLOT(onTrimReleased()));
connect(vJoyRight, SIGNAL(trimSliderMoved(int,int)), this, SLOT(onTrimSliderMoved(int,int)));

timer->setInterval(10);
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent()));
connect(timer, SIGNAL(timeout()), radioUiWidget, SLOT(updateUi()));
}

SimulatorWidget::~SimulatorWidget()
Expand Down Expand Up @@ -443,11 +447,14 @@ void SimulatorWidget::start()

void SimulatorWidget::stop()
{
timer->stop();
simulator->stop();
if (saveTempRadioData) {
startupData.fill(0, getEEpromSize(m_board));
simulator->readEepromData(startupData);
if (timer)
timer->stop();
if (simulator) {
simulator->stop();
if (saveTempRadioData) {
startupData.fill(0, getEEpromSize(m_board));
simulator->readEepromData(startupData);
}
}
}

Expand Down Expand Up @@ -629,18 +636,13 @@ void SimulatorWidget::setupJoysticks()

void SimulatorWidget::setupTimer()
{
if (timer) {
if (!timer)
return;

if (timer->isActive())
timer->stop();
disconnect(timer, 0, this, 0);
disconnect(timer, 0, radioUiWidget, 0);
timer->deleteLater();
timer = NULL;
}
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent()));
connect(timer, SIGNAL(timeout()), radioUiWidget, SLOT(updateUi()));

timer->start(10);
timer->start();
}

void SimulatorWidget::restoreRadioWidgetsState()
Expand Down

0 comments on commit d90b1e0

Please sign in to comment.