Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[Qt] Sanitize QSize → mbgl::Size conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Apr 3, 2017
1 parent c57f051 commit c67c189
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions platform/qt/src/qmapboxgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ auto fromQStringList(const QStringList &list)
return strings;
}

mbgl::Size sanitizedSize(const QSize& size) {
return mbgl::Size {
size.width() <= 0 ? 0 : static_cast<uint32_t>(size.width()),
size.height() <= 0 ? 0 : static_cast<uint32_t>(size.height())
};
};

std::unique_ptr<const mbgl::SpriteImage> toSpriteImage(const QImage &sprite) {
const QImage swapped = sprite
.rgbSwapped()
Expand Down Expand Up @@ -433,6 +440,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()) {
Expand Down Expand Up @@ -1079,8 +1088,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));
}

/*!
Expand Down Expand Up @@ -1547,14 +1555,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());
Expand All @@ -1570,7 +1579,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() {
Expand Down

0 comments on commit c67c189

Please sign in to comment.