From 0b81e828add7e77fd3aecaf46955f7d1a84321ae Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Wed, 12 Feb 2020 23:50:23 +0100 Subject: Fix segmentation fault due to null pointer usage Change-Id: I3b030728b32af6e340738583f78b2cfb0d2df11a Reviewed-by: Fabian Kosmale Reviewed-by: Alex Blasche --- .../qdeclarativepolylinemapitem.cpp | 41 +++++++++++++++++++--- .../qdeclarativepolylinemapitem_p_p.h | 26 ++------------ 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index f914b36d..d40c1b79 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -1947,8 +1947,8 @@ bool QGeoMapItemLODGeometry::isLODActive(unsigned int lod) const class PolylineSimplifyTask : public QRunnable { public: - PolylineSimplifyTask(QSharedPointer > &input, // reference as it gets copied in the nested call - QSharedPointer > &output, + PolylineSimplifyTask(const QSharedPointer > &input, // reference as it gets copied in the nested call + const QSharedPointer > &output, double leftBound, unsigned int zoom, QSharedPointer &working) @@ -1958,6 +1958,8 @@ public: , m_output(output) , m_working(working) { + Q_ASSERT(!input.isNull()); + Q_ASSERT(!output.isNull()); } ~PolylineSimplifyTask() override; @@ -1967,9 +1969,11 @@ public: // Skip sending notifications for now. Updated data will be picked up eventually. // ToDo: figure out how to connect a signal from here to a slot in the item. *m_working = QGeoMapPolylineGeometryOpenGL::zoomToLOD(m_zoom); - *m_output = QGeoMapPolylineGeometryOpenGL::getSimplified( *m_input, + const QVector res = + QGeoMapPolylineGeometryOpenGL::getSimplified( *m_input, m_leftBound, QGeoMapPolylineGeometryOpenGL::zoomForLOD(m_zoom)); + *m_output = res; *m_working = 0; } @@ -1979,12 +1983,14 @@ public: QSharedPointer m_working; }; -void QGeoMapItemLODGeometry::enqueueSimplificationTask(QSharedPointer > &input, - QSharedPointer > &output, +void QGeoMapItemLODGeometry::enqueueSimplificationTask(const QSharedPointer > &input, + const QSharedPointer > &output, double leftBound, unsigned int zoom, QSharedPointer &working) { + Q_ASSERT(!input.isNull()); + Q_ASSERT(!output.isNull()); PolylineSimplifyTask *task = new PolylineSimplifyTask(input, output, leftBound, @@ -2032,6 +2038,31 @@ void QGeoMapItemLODGeometry::selectLOD(unsigned int zoom, double leftBound, bool } } +void QGeoMapItemLODGeometry::selectLODOnDataChanged(unsigned int zoom, double leftBound) const +{ + unsigned int lod = zoomToLOD(zoom); + if (lod > 0) { + // Generate ZL 1 as fallback for all cases != 0. Do not do if 0 is requested + // (= old behavior, LOD disabled) + m_verticesLOD[1] = QSharedPointer>( + new QVector); + *m_verticesLOD[1] = getSimplified( *m_verticesLOD[0], + leftBound, + zoomForLOD(0)); + } + if (lod > 1) { + if (!m_verticesLOD[lod]) + m_verticesLOD[lod] = QSharedPointer>( + new QVector); + enqueueSimplificationTask( m_verticesLOD.at(0), + m_verticesLOD[lod], + leftBound, + zoom, + m_working); + } + m_screenVertices = m_verticesLOD[qMin(lod, 1)].data(); // return only 0,1 synchronously +} + unsigned int QGeoMapItemLODGeometry::zoomToLOD(unsigned int zoom) { unsigned int res; diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem_p_p.h b/src/location/declarativemaps/qdeclarativepolylinemapitem_p_p.h index 35d52790..2a588222 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem_p_p.h +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem_p_p.h @@ -249,33 +249,13 @@ public: double leftBoundWrapped, unsigned int zoom); - static void enqueueSimplificationTask(QSharedPointer > &input, // reference as it gets copied in the nested call - QSharedPointer > &output, + static void enqueueSimplificationTask(const QSharedPointer > &input, // reference as it gets copied in the nested call + const QSharedPointer > &output, double leftBound, unsigned int zoom, QSharedPointer &working); - void selectLODOnDataChanged(unsigned int zoom, double leftBound) const - { - unsigned int lod = zoomToLOD(zoom); - if (lod > 0) { - // Generate ZL 1 as fallback for all cases != 0. Do not do if 0 is requested - // (= old behavior, LOD disabled) - m_verticesLOD[1] = QSharedPointer>( - new QVector); - *m_verticesLOD[1] = getSimplified( *m_verticesLOD[0], - leftBound, - zoomForLOD(0)); - } - if (lod > 1) { - enqueueSimplificationTask( m_verticesLOD.at(0), - m_verticesLOD[zoomToLOD(zoom)], - leftBound, - zoom, - m_working); - } - m_screenVertices = m_verticesLOD[qMin(lod, 1)].data(); - } + void selectLODOnDataChanged(unsigned int zoom, double leftBound) const; bool selectLODOnLODMismatch(unsigned int zoom, double leftBound, bool closed) const { -- cgit v1.2.1