Skip to content

Commit

Permalink
Fix use-after-delete with fast clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tatokis committed Jun 18, 2020
1 parent 086c6ea commit 281ea7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ void MainWindow::registerUpdate(TrnEmu::Register r, TrnEmu::OperationType t, qui
pcarrowpos = 0;
break;
}
// Stop any animations if we are about to delete the PC
animator->cancelIfInUse(ui->memoryTable->item(val, 0));
// Set it to the new PC position
ui->memoryTable->setItem(val, 0, arrow);
// Update the "pointer"
Expand Down
14 changes: 14 additions & 0 deletions tablewidgetitemanimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,17 @@ TableWidgetItemAnimator::~TableWidgetItemAnimator()
if(labelbg)
delete labelbg;
}

void TableWidgetItemAnimator::cancelIfInUse(QTableWidgetItem* itm)
{
if(itm == readItemThird)
{
readAnim->stop();
readItemThird = readItemSecond = readItemFirst = nullptr;
}
else if(itm == writeItemThird)
{
writeAnim->stop();
writeItemThird = writeItemSecond = writeItemFirst = nullptr;
}
}
2 changes: 1 addition & 1 deletion tablewidgetitemanimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class TableWidgetItemAnimator : public QObject
void setWriteColour(const QColor& c);
// Apparently the getters can just be stubs
inline QColor getColour() { return QColor(); }

~TableWidgetItemAnimator();
void cancelIfInUse(QTableWidgetItem* itm);

signals:

Expand Down

0 comments on commit 281ea7f

Please sign in to comment.