From b25c8f043b1622f8e4f4ddb16956861969786c00 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 29 Mar 2017 18:53:10 +0300 Subject: =?UTF-8?q?[Qt]=20Sanitize=20QSize=20=E2=86=92=20mbgl::Size=20conv?= =?UTF-8?q?ersion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/android/build.gradle | 2 +- platform/qt/src/qmapboxgl.cpp | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/platform/android/build.gradle b/platform/android/build.gradle index 5e45232716..120c0219e4 100644 --- a/platform/android/build.gradle +++ b/platform/android/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.1' classpath 'com.amazonaws:aws-devicefarm-gradle-plugin:1.2' classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.1' } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index d700fe4f11..7cb0541a75 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -79,6 +80,13 @@ auto fromQStringList(const QStringList &list) return strings; } +mbgl::Size sanitizedSize(const QSize& size) { + return mbgl::Size { + mbgl::util::max(0u, static_cast(size.width())), + mbgl::util::max(0u, static_cast(size.height())), + }; +}; + std::unique_ptr toSpriteImage(const QImage &sprite) { const QImage swapped = sprite .rgbSwapped() @@ -433,6 +441,8 @@ void QMapboxGLSettings::setApiBaseUrl(const QString& url) QMapboxGL::QMapboxGL(QObject *parent, const QMapboxGLSettings &settings, const QSize& size, qreal pixelRatio) : QObject(parent) { + assert(!size.isEmpty()); + // Multiple QMapboxGL running on the same thread // will share the same mbgl::util::RunLoop if (!loop.hasLocalData()) { @@ -1079,8 +1089,7 @@ void QMapboxGL::resize(const QSize& size, const QSize& framebufferSize) d_ptr->size = size; d_ptr->fbSize = framebufferSize; - d_ptr->mapObj->setSize( - { static_cast(size.width()), static_cast(size.height()) }); + d_ptr->mapObj->setSize(sanitizedSize(size)); } /*! @@ -1547,14 +1556,15 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin settings.assetPath().toStdString(), settings.cacheDatabaseMaximumSize())) , threadPool(mbgl::sharedThreadPool()) - , mapObj(std::make_unique( - *this, mbgl::Size{ static_cast(size.width()), static_cast(size.height()) }, - pixelRatio, *fileSourceObj, *threadPool, - mbgl::MapMode::Continuous, - static_cast(settings.contextMode()), - static_cast(settings.constrainMode()), - static_cast(settings.viewportMode()))) { + mapObj = std::make_unique( + *this, sanitizedSize(size), + pixelRatio, *fileSourceObj, *threadPool, + mbgl::MapMode::Continuous, + static_cast(settings.contextMode()), + static_cast(settings.constrainMode()), + static_cast(settings.viewportMode())); + qRegisterMetaType("QMapboxGL::MapChange"); fileSourceObj->setAccessToken(settings.accessToken().toStdString()); @@ -1570,7 +1580,7 @@ QMapboxGLPrivate::~QMapboxGLPrivate() } mbgl::Size QMapboxGLPrivate::framebufferSize() const { - return { static_cast(fbSize.width()), static_cast(fbSize.height()) }; + return sanitizedSize(fbSize); } void QMapboxGLPrivate::updateAssumedState() { -- cgit v1.2.1