diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 1499def75da..989f4eafc76 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -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(size.width()), + size.height() <= 0 ? 0 : static_cast(size.height()) + }; +}; + std::unique_ptr toSpriteImage(const QImage &sprite) { const QImage swapped = sprite .rgbSwapped() @@ -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()) { @@ -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(size.width()), static_cast(size.height()) }); + d_ptr->mapObj->setSize(sanitizedSize(size)); } /*! @@ -1547,14 +1555,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 +1579,7 @@ QMapboxGLPrivate::~QMapboxGLPrivate() } mbgl::Size QMapboxGLPrivate::framebufferSize() const { - return { static_cast(fbSize.width()), static_cast(fbSize.height()) }; + return sanitizedSize(fbSize); } void QMapboxGLPrivate::updateAssumedState() {