summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-03-29 18:53:10 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-04-10 18:01:28 +0300
commitb25c8f043b1622f8e4f4ddb16956861969786c00 (patch)
treebc1bcd2070e5b448e6e81c2c68ad219d7b419a12
parente5aa4d70cd7b39302ddf1ec4df240a14accfb474 (diff)
downloadqtlocation-mapboxgl-b25c8f043b1622f8e4f4ddb16956861969786c00.tar.gz
[Qt] Sanitize QSize → mbgl::Size conversion
-rw-r--r--platform/android/build.gradle2
-rw-r--r--platform/qt/src/qmapboxgl.cpp30
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 <mbgl/map/camera.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/map/backend_scope.hpp>
+#include <mbgl/math/minmax.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/conversion/source.hpp>
@@ -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<uint32_t>(size.width())),
+ mbgl::util::max(0u, static_cast<uint32_t>(size.height())),
+ };
+};
+
std::unique_ptr<const mbgl::SpriteImage> 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<uint32_t>(size.width()), static_cast<uint32_t>(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<mbgl::Map>(
- *this, mbgl::Size{ static_cast<uint32_t>(size.width()), static_cast<uint32_t>(size.height()) },
- pixelRatio, *fileSourceObj, *threadPool,
- mbgl::MapMode::Continuous,
- static_cast<mbgl::GLContextMode>(settings.contextMode()),
- static_cast<mbgl::ConstrainMode>(settings.constrainMode()),
- static_cast<mbgl::ViewportMode>(settings.viewportMode())))
{
+ mapObj = std::make_unique<mbgl::Map>(
+ *this, sanitizedSize(size),
+ pixelRatio, *fileSourceObj, *threadPool,
+ mbgl::MapMode::Continuous,
+ static_cast<mbgl::GLContextMode>(settings.contextMode()),
+ static_cast<mbgl::ConstrainMode>(settings.constrainMode()),
+ static_cast<mbgl::ViewportMode>(settings.viewportMode()));
+
qRegisterMetaType<QMapboxGL::MapChange>("QMapboxGL::MapChange");
fileSourceObj->setAccessToken(settings.accessToken().toStdString());
@@ -1570,7 +1580,7 @@ QMapboxGLPrivate::~QMapboxGLPrivate()
}
mbgl::Size QMapboxGLPrivate::framebufferSize() const {
- return { static_cast<uint32_t>(fbSize.width()), static_cast<uint32_t>(fbSize.height()) };
+ return sanitizedSize(fbSize);
}
void QMapboxGLPrivate::updateAssumedState() {