Fix segfaults when add to graphing window for signal not found in DBC

This commit is contained in:
Matthias Kelch
2021-09-27 17:52:30 +02:00
parent 37b9c821e5
commit 31c26a7df0
+38 -18
View File
@@ -535,6 +535,7 @@ void MainWindow::setupAddToNewGraph()
setupSendToLatestGraphWindow(); //then call the other function to finish setupSendToLatestGraphWindow(); //then call the other function to finish
} }
void MainWindow::setupSendToLatestGraphWindow() void MainWindow::setupSendToLatestGraphWindow()
{ {
if (!lastGraphingWindow) showGraphingWindow(); if (!lastGraphingWindow) showGraphingWindow();
@@ -542,26 +543,45 @@ void MainWindow::setupSendToLatestGraphWindow()
QString signalName = getSignalNameFromPosition(contextMenuPosition); QString signalName = getSignalNameFromPosition(contextMenuPosition);
param.ID = getMessageIDFromPosition(contextMenuPosition); param.ID = getMessageIDFromPosition(contextMenuPosition);
DBC_MESSAGE *msg = dbcHandler->findMessageForFilter(param.ID, nullptr); DBC_MESSAGE *msg = dbcHandler->findMessageForFilter(param.ID, nullptr);
DBC_SIGNAL *sig = msg->sigHandler->findSignalByName(signalName); if(msg)
param.associatedSignal = sig; {
param.bias = sig->bias; DBC_SIGNAL *sig = msg->sigHandler->findSignalByName(signalName);
param.intelFormat = sig->intelByteOrder; if(sig)
param.isSigned = sig->valType == SIGNED_INT ? true : false; {
param.numBits = sig->signalSize; param.associatedSignal = sig;
param.scale = sig->factor; param.bias = sig->bias;
param.startBit = sig->startBit; param.intelFormat = sig->intelByteOrder;
param.stride = 1; param.isSigned = sig->valType == SIGNED_INT ? true : false;
param.graphName = sig->name; param.numBits = sig->signalSize;
param.lineColor = QColor(QRandomGenerator::global()->bounded(160), QRandomGenerator::global()->bounded(160), QRandomGenerator::global()->bounded(160)); param.scale = sig->factor;
param.lineWidth = 1; param.startBit = sig->startBit;
param.fillColor = QColor(128, 128, 128, 0); param.stride = 1;
param.mask = 0xFFFFFFFFFFFFFFFFull; param.graphName = sig->name;
param.drawOnlyPoints = false; param.lineColor = QColor(QRandomGenerator::global()->bounded(160), QRandomGenerator::global()->bounded(160), QRandomGenerator::global()->bounded(160));
param.pointType = 0; param.lineWidth = 1;
param.fillColor = QColor(128, 128, 128, 0);
param.mask = 0xFFFFFFFFFFFFFFFFull;
param.drawOnlyPoints = false;
param.pointType = 0;
lastGraphingWindow->createGraph(param); //add the new graph to the window lastGraphingWindow->createGraph(param); //add the new graph to the window
}
else
{
QMessageBox msgbox;
QString boxmsg = "Cannot find ID 0x" + QStringLiteral("%1").arg(param.ID, 3, 16, QLatin1Char('0')) + " in DBC message " + msg->name + ". Not adding graph.";
msgbox.setText(boxmsg);
msgbox.exec();
}
}
else
{
QMessageBox msgbox;
QString boxmsg = "Cannot find ID 0x" + QStringLiteral("%1").arg(param.ID, 3, 16, QLatin1Char('0')) + " in DBC file(s). Not adding graph.";
msgbox.setText(boxmsg);
msgbox.exec();
}
} }
void MainWindow::interpretToggled(bool state) void MainWindow::interpretToggled(bool state)
{ {
model->setInterpretMode(state); model->setInterpretMode(state);