From 6d928bb664d056bb2ee29190bbc82a686721df7a Mon Sep 17 00:00:00 2001 From: Jesse Litton Date: Fri, 26 May 2017 06:55:24 -0500 Subject: [PATCH] Fix Region-change Crash --- docs/RELEASES | 3 +++ src/imp.pro | 2 +- src/mainwindow.cpp | 14 ++++++-------- src/mainwindow.h | 1 + src/map.cpp | 8 -------- src/mapshape.cpp | 26 ++++++++++---------------- src/mapshape.h | 9 ++++----- src/meta.h | 4 ++-- src/parser.cpp | 6 +++++- src/parser.h | 7 +++++-- src/svgmapview.cpp | 17 +++++++++++++++++ src/svgmapview.h | 2 +- src/systemshape.cpp | 8 +++----- src/systemshape.h | 3 ++- 14 files changed, 60 insertions(+), 50 deletions(-) diff --git a/docs/RELEASES b/docs/RELEASES index faaba9b..efc2c70 100644 --- a/docs/RELEASES +++ b/docs/RELEASES @@ -1,3 +1,6 @@ +0.8.8 - Fixes crashes when changing regions due to access of invalidated + logInfo pointers. + 0.8.7 - Fixed avatars not showing for some users on Windows due to missing DLLs. diff --git a/src/imp.pro b/src/imp.pro index bfb8e6a..33d7177 100644 --- a/src/imp.pro +++ b/src/imp.pro @@ -12,7 +12,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = imp TEMPLATE = app -VERSION = 0.8.7 +VERSION = 0.8.8 QMAKE_TARGET_COMPANY = EternalDusk QMAKE_TARGET_DESCRIPTION = Eve Online Intelligence Management Program QMAKE_TARGET_COPYRIGHT = (c) Copyright 2016-2017 Jesse Litton diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0399065..34451ee 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -344,14 +344,7 @@ void MainWindow::loadMap() regionMap = NULL; } regionMap = new Map(this); - ui->mapView->setMap(regionMap); - connect(regionMap, &Map::lineAdded, - ui->mapView, &SvgMapView::gotLine); - connect(regionMap, &Map::systemAdded, - ui->mapView, &SvgMapView::gotSystem); - connect(regionMap, &Map::systemPosition, - ui->mapView, &SvgMapView::gotSystemPosition); QNetworkRequest request(QUrl(options.getMapPath() + options.getRegion() + ".svg")); @@ -648,7 +641,7 @@ void MainWindow::initParsing() { parser->deleteLater(); } - parser = new Parser(this); + parser = new Parser(++parserGeneration, this); parser->setMap(*regionMap); if(lc != NULL) @@ -1009,6 +1002,11 @@ void MainWindow::fileChanged(const QString &absoluteFilePath) foreach (MessageInfo message, messages) { + // If they switch regions while parsing messages, + // discard the ones on the queue. + if(message.parserGeneration != parserGeneration) + break; + if(!mapLoading) doUserActions(message); diff --git a/src/mainwindow.h b/src/mainwindow.h index c0d9d65..8991992 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -170,6 +170,7 @@ private slots: LogCatcher* lc = NULL; Parser* parser = NULL; + uint parserGeneration = 0; QNetworkAccessManager manager; QNetworkReply* reply; diff --git a/src/map.cpp b/src/map.cpp index f080379..5674e62 100755 --- a/src/map.cpp +++ b/src/map.cpp @@ -36,14 +36,6 @@ Map::Map(QObject *parent) : QObject(parent) void Map::setRefresh(int msecs) { m_timer->setInterval(msecs); - /* - if(m_timer != NULL) - { - m_timer->deleteLater(); - } - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(updateActiveSystems())); -*/ } void Map::startUpdates() diff --git a/src/mapshape.cpp b/src/mapshape.cpp index 5499e40..ff24e8a 100644 --- a/src/mapshape.cpp +++ b/src/mapshape.cpp @@ -27,31 +27,26 @@ #include #include -MapShape::MapShape() +MapShape::MapShape(QGraphicsItem *parentItem) : QGraphicsSvgItem(parentItem) { - renderer = new QSvgRenderer(); - connect(renderer, &QSvgRenderer::repaintNeeded, - this, &MapShape::repainter ); } MapShape::MapShape(QSvgRenderer* svgRenderer, - const QString& name, - const QString& itemId) + QString name, + QString itemId, + QGraphicsItem* parentItem) : QGraphicsSvgItem(parentItem) { - renderer = svgRenderer; + this->setSharedRenderer(svgRenderer); + shapeName = name; - setSharedRenderer(renderer); setElementId(itemId); - connect(renderer, &QSvgRenderer::repaintNeeded, - this, &MapShape::repainter); + + /*connect(renderer, &QSvgRenderer::repaintNeeded, + this, &MapShape::repainter);*/ } MapShape::~MapShape() { - if(renderer != NULL) - { - renderer->deleteLater(); - } } void MapShape::repainter() @@ -103,8 +98,7 @@ void MapShape::load(const QString& fileName) void MapShape::rebuildSvg() { - renderer->load(domDoc.toByteArray()); - setSharedRenderer(renderer); + renderer()->load(domDoc.toByteArray()); setElementId(""); setFlags(QGraphicsItem::ItemClipsToShape); diff --git a/src/mapshape.h b/src/mapshape.h index 3e57328..67e31e1 100644 --- a/src/mapshape.h +++ b/src/mapshape.h @@ -32,11 +32,11 @@ class MapShape : public QGraphicsSvgItem { public: - explicit MapShape(); + explicit MapShape(QGraphicsItem *parentItem = nullptr); MapShape(QSvgRenderer* svgRenderer, - const QString& name, - const QString& itemId);//, - //QGraphicsView *view); + QString name, + QString itemId, + QGraphicsItem *parentItem = nullptr); ~MapShape(); void paint(QPainter * painter, @@ -67,7 +67,6 @@ public slots: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); QString shapeName; - QSvgRenderer* renderer; private: bool rotationLocked; diff --git a/src/meta.h b/src/meta.h index 8def76b..519bdd6 100644 --- a/src/meta.h +++ b/src/meta.h @@ -27,8 +27,8 @@ static const struct Version { Version(){} - QString release = "0.8.7"; //VERSION; - QString name = "Lupine Fresh Scent"; + QString release = "0.8.8"; //VERSION; + QString name = "Lycrash vs. Silver Pointers"; QString styleHeader1 = ""; QString styleFooter1 = ""; diff --git a/src/parser.cpp b/src/parser.cpp index ad38fa5..b395e89 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -32,8 +32,10 @@ using namespace std; -Parser::Parser(QObject *parent) : QObject(parent) +Parser::Parser(uint generation, QObject *parent) : QObject(parent) { + this->generation = generation; + ignoreChars = "[\\\\_=!@#$%^&\\*,\\.\\[\\]\\(\\)\\{\\}\\?]"; // "\\_=!@#$%^&*,./[](){}?" // Load words, channels, and ships from files @@ -101,6 +103,7 @@ QList Parser::fileChanged(const QString& path, int maxEntries, bool if (sysIdRegExp.indexIn(line) != -1 && localChannels.contains(channel)) { MessageInfo systemChange; + systemChange.parserGeneration = generation; systemChange.flags.append(MessageFlag::SYSTEM_CHANGE); systemChange.systems.append(regionMap->getSystemById(sysIdRegExp.cap(1))); systemChange.text = "System changed to " + systemChange.systems[0]; @@ -134,6 +137,7 @@ QList Parser::fileChanged(const QString& path, int maxEntries, bool MessageInfo newMessage = parseLine(lines[i].trimmed().remove(0xfeff)); + newMessage.parserGeneration = generation; newMessage.logInfo = &fileMap[path]; if(newMessage.systems.length() > 0) { diff --git a/src/parser.h b/src/parser.h index 457c665..cf6a15a 100755 --- a/src/parser.h +++ b/src/parser.h @@ -50,8 +50,9 @@ struct LogInfo struct MessageInfo { + uint parserGeneration = 0; QString originalLine; - bool indecipherable = false; + bool indecipherable = false; LogInfo* logInfo; @@ -73,7 +74,7 @@ class Parser : public QObject { Q_OBJECT public: - explicit Parser(QObject *parent = 0); + explicit Parser(uint generation, QObject *parent = 0); void setMap(Map& map); QList fileChanged(const QString& path, int maxEntries = 0, bool initialLoad = false); QSet getLocalChannels(); @@ -87,6 +88,8 @@ class Parser : public QObject public slots: private: + uint generation = 0; + QString lastListener; QString lastLocalSystem; diff --git a/src/svgmapview.cpp b/src/svgmapview.cpp index 024a3f6..673e58e 100755 --- a/src/svgmapview.cpp +++ b/src/svgmapview.cpp @@ -430,6 +430,9 @@ void SvgMapView::gotPilotLocation(const QString& pilotName, const QString& syste void SvgMapView::gotSystemShapesFile(QString shapesFile) { + qDebug() << "SvgMapView::gotSystemShapesFile(" << shapesFile << + ") - systemRenderer = " << systemRenderer; + if(systemRenderer != NULL) { systemRenderer->deleteLater(); @@ -650,6 +653,8 @@ void SvgMapView::gotSystem(const QString& mixedName, QPointF position, const QSt { // TODO: Make a new starSystem item that encapsulates all these components? + qDebug() << "SvgMapView::gotSystem(" << mixedName << "," << position << "," << systemClass << "," << description << ")"; + QString name = mixedName.toUpper(); SystemShape* shape = new SystemShape(systemRenderer, name, @@ -701,6 +706,18 @@ void SvgMapView::gotSystemPosition( setTextPosition(m_texts[name + ":time"], position, timeOffset); } +void SvgMapView::setMap(Map* m) +{ + m_map = m; + + connect(m_map, &Map::lineAdded, + this, &SvgMapView::gotLine); + connect(m_map, &Map::systemAdded, + this, &SvgMapView::gotSystem); + connect(m_map, &Map::systemPosition, + this, &SvgMapView::gotSystemPosition); +} + void SvgMapView::setTextPosition(QGraphicsTextItem* ti, QPointF position, QPointF offset) { QPointF center = ti->boundingRect().bottomRight() * .5; diff --git a/src/svgmapview.h b/src/svgmapview.h index 31bc39a..a84f414 100755 --- a/src/svgmapview.h +++ b/src/svgmapview.h @@ -43,7 +43,7 @@ class SvgMapView : public QGraphicsView explicit SvgMapView(QWidget *parent = 0); ~SvgMapView(); - void setMap(Map* m){m_map = m;} + void setMap(Map* m); void clearLines(); void clearMap(); diff --git a/src/systemshape.cpp b/src/systemshape.cpp index 893c4c0..c138ac0 100644 --- a/src/systemshape.cpp +++ b/src/systemshape.cpp @@ -5,15 +5,13 @@ SystemShape::SystemShape(QSvgRenderer* svgRenderer, QString name, - QString c) - : MapShape(svgRenderer, name, c) + QString c, + QGraphicsItem *parentItem) + : MapShape(svgRenderer, name, c, parentItem) { shapeName = name + ":system"; className = c; -// renderer = svgRenderer; -// setSharedRenderer(renderer); -// setElementId(className); setFlags(QGraphicsItem::ItemClipsToShape); setZValue(0); setGraphicsEffect(0); diff --git a/src/systemshape.h b/src/systemshape.h index a4e2153..ad803d0 100644 --- a/src/systemshape.h +++ b/src/systemshape.h @@ -10,7 +10,8 @@ class SystemShape : public MapShape public: SystemShape(QSvgRenderer* svgRenderer, QString name, - QString className); + QString className, + QGraphicsItem *parentItem = nullptr); ~SystemShape(); void setColor(const QColor& c);