[Qt] Sanitize QSize → mbgl::Size conversion
This commit is contained in:
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user