maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   [SFOS] Mapbox GL Native QML plugin (https://talk.maemo.org/showthread.php?t=99953)

rinigus 2017-10-12 16:52

Mapbox GL Native QML plugin
 
2 Attachment(s)
This is an announcement of Mapbox GL Native (https://github.com/mapbox/mapbox-gl-native) QML plugin that can be used to display and interact with the maps in QML application. This is a fast, OpenGL accelerated, high-quality rendering-providing map component that should be easy to use for app developers.

It is recommended to use this as QML plugin and use it through QML interface. It is possible to use the developed plugin by incorporating it on C++ source level, but then you will need newer gcc (>=4.9). When using QML interface, older gcc provided with SFOS is sufficient.

I am starting this thread to provide simple to find information on this QML plugin and to mark the readiness of the plugin for general development of map applications. This thread could be considered as a continuation of "brainstorm" thread https://talk.maemo.org/showthread.php?t=93358 and the step towards implementation of the original brainstorm request.

Project GitHub page: https://github.com/rinigus/mapbox-gl-qml

Documentation: https://github.com/rinigus/mapbox-gl.../master/api.md

License: LGPL3. For the gesture area interaction component, MIT.

Requirements: Qt >= 5.6

SFOS packaging:

OBS: https://build.merproject.org/package...s/mapboxgl-qml

OpenRepos: https://openrepos.net/content/rinigu...indings-qt-qml

C++ development library

QMapboxGL for C++ development is packaged using https://github.com/rinigus/pkg-mapbox-gl-native and available at https://build.merproject.org/package...maps/qmapboxgl.

Example code

As an example, see a QML item that would show a map that can be zoomed and panned

Code:

import QtQuick 2.0
import Sailfish.Silica 1.0
import MapboxMap 1.0
import QtPositioning 5.3

Page
{
    id: page

    MapboxMap {
        id: map
        anchors.fill: parent

        center: QtPositioning.coordinate(60.170448, 24.942046)
        zoomLevel: 4.0
        minimumZoomLevel: 0
        maximumZoomLevel: 20
        pixelRatio: 3.0

        accessToken: "INSERT_MAPBOX_ACCESS_TOKEN_HERE"
        cacheDatabaseMaximalSize: 20*1024*1024
        cacheDatabasePath: "/tmp/mbgl-cache.db"

        styleUrl: "mapbox://styles/mapbox/outdoors-v10"

        MapboxMapGestureArea {
            map: map
        }
    }
}

Donations: https://liberapay.com/rinigus

Current issues

Issues are followed on GitHub project page at https://github.com/rinigus/mapbox-gl-qml/issues

Current main issue is crashes on Jolla 1 and Photon Q.

Obligatory screenshots

Poor Maps prototype showing
  • a road found by routing component incorporated into the map under the layer with the labels
  • POIs drawn on the map with the labels and interactive QML dialog following geographical location of POI
.

rinigus 2017-10-13 10:04

Re: Mapbox GL Native QML plugin
 
To test whether very primitive style helps against crashes on Jolla 1, maybe someone could test QML-only app? For that:

* Install https://build.merproject.org/package...s/mapboxgl-qml (download from http://repo.merproject.org/obs/home:...mv7hl/armv7hl/)

* Get QML-only demo at https://github.com/rinigus/mapbox-de...aster/qml-only . You would need the both QML files in this directory

* run
Code:

qmlscene mapbox-gl-qml.qml
Zeta has reported absence of crashes in C++ compiled app with dynamically linked libstdc++ (https://talk.maemo.org/showpost.php?...&postcount=125) and crashing on start with the statically linked libstdc++ (https://talk.maemo.org/showpost.php?...&postcount=123).

At present, QML plugin is statically linked with newer stdc++. So, I wonder if that would work on J1. On other devices I don't expect any problems (except Photon Q).

Zeta 2017-10-13 20:25

Re: Mapbox GL Native QML plugin
 
Quote:

Originally Posted by rinigus (Post 1536658)
To test whether very primitive style helps against crashes on Jolla 1, maybe someone could test QML-only app? For that:

* Install https://build.merproject.org/package...s/mapboxgl-qml (download from http://repo.merproject.org/obs/home:...mv7hl/armv7hl/)

* Get QML-only demo at https://github.com/rinigus/mapbox-de...aster/qml-only . You would need the both QML files in this directory

* run
Code:

qmlscene mapbox-gl-qml.qml
Zeta has reported absence of crashes in C++ compiled app with dynamically linked libstdc++ (https://talk.maemo.org/showpost.php?...&postcount=125) and crashing on start with the statically linked libstdc++ (https://talk.maemo.org/showpost.php?...&postcount=123).

At present, QML plugin is statically linked with newer stdc++. So, I wonder if that would work on J1. On other devices I don't expect any problems (except Photon Q).

I tested with this new simple QML app, and first comment is that it looks great ! It is fast (no visible lags, adapts quite well to the zoom level), so a big applause once more to have been able to provide something like this to the Sailfish community.

Now for the tests itself:
* Played with it for quite some time with this basic red theme, and didn't notice anything wrong. I moved/zoomed around as fast as possible (in the range of "normal use" to "crazy as hell") without any crash.
* Seeing at it looks like it was working well, I edited the QML to remove the "jsonStyle" part, to get back to the standard map (it is really easy to do, good job!), and I got it working for quite some time. As a lot is now displayed, it is fun to zoom/move/unzoom/move somewhere else. At the end, I got another crash (segmentation fault). it can work from 10 to 30 seconds before the crash when torturing it (from world to street level and back to another country streets in seconds). Using it a bit less fast (looking around a single city), it can last close to 1 minutes. And if only zooming in a park and not touching it, except to keep it from shutting screen, then it seems to run forever (I stopped after 7 minutes, by moving around as fast as possible and it then crashed).

So at this end, the way it is used impacts the time it takes to crash, and the simple red theme, if it could finally crash, does it after a long time of torturing it.
Likely some resources exhaustion (network, ram, gpu, handles of something ?), some timing issues (the more it is to do, the more likely a collision can occur), memory/stack corruption, or a specific program path that leads to the crash when a specific item has to be computed/drawn ? Nothing easy to find so...
The main differences between the Jolla1 and the other are mainly the gpu driver, and some more limited hardware. There are also different kernel and the like.

With full map, the crash can appear anywhere it seems. gdb output is:
Code:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x4816e3a0 (LWP 5624)]
0x4553db2c in mbgl::VectorTileLayer::getFeature(unsigned int) const () from /usr/lib/qt5/qml/MapboxMap/libqmlmapboxglplugin.so
(gdb) bt full
#0  0x4553db2c in mbgl::VectorTileLayer::getFeature(unsigned int) const () from /usr/lib/qt5/qml/MapboxMap/libqmlmapboxglplugin.so
No symbol table info available.
#1  0x454b0290 in mbgl::GeometryTileWorker::redoLayout() () from /usr/lib/qt5/qml/MapboxMap/libqmlmapboxglplugin.so
No symbol table info available.
#2  0x4acb1b60 in ?? ()
Cannot access memory at address 0x0
No symbol table info available.
#3  0x4acb1b60 in ?? ()
Cannot access memory at address 0x0
No symbol table info available.
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Or :
Code:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x481643a0 (LWP 5759)]
0x40edb734 in malloc_consolidate (av=av@entry=0x44d00010) at malloc.c:4165
4165        malloc.c: No such file or directory.
(gdb) bt
#0  0x40edb734 in malloc_consolidate (av=av@entry=0x44d00010) at malloc.c:4165
#1  0x40edd13e in _int_malloc (av=av@entry=0x44d00010, bytes=bytes@entry=512) at malloc.c:3423
#2  0x40ede77c in __GI___libc_malloc (bytes=512) at malloc.c:2891
#3  0x40d8d7a8 in operator new(unsigned int) () from /usr/lib/libstdc++.so.6
#4  0x456d0716 in void std::vector<protozero::data_view, std::allocator<protozero::data_view> >::_M_emplace_back_aux<protozero::data_view>(protozero::data_view&&) ()
  from /usr/lib/qt5/qml/MapboxMap/libqmlmapboxglplugin.so
#5  0x456d0a3a in mapbox::vector_tile::layer::layer(protozero::data_view const&) () from /usr/lib/qt5/qml/MapboxMap/libqmlmapboxglplugin.so
#6  0x456cedf6 in mbgl::VectorTileLayer::VectorTileLayer(std::shared_ptr<std::string const>, protozero::data_view const&) () from /usr/lib/qt5/qml/MapboxMap/libqmlmapboxglplugin.so
#7  0x456cef50 in mbgl::VectorTileData::getLayer(std::string const&) const () from /usr/lib/qt5/qml/MapboxMap/libqmlmapboxglplugin.so
#8  0x4563eeea in mbgl::GeometryTileWorker::redoLayout() () from /usr/lib/qt5/qml/MapboxMap/libqmlmapboxglplugin.so
#9  0x482973c0 in ?? ()
Cannot access memory at address 0x0


tmi 2017-10-13 21:12

Re: Mapbox GL Native QML plugin
 
Zeta's testing was way more complete than mine. I only played with the red theme a couple of minutes and it seemed fluent until exit

The output:
Code:

[nemo@Sailfish mapbox]$ qmlscene mapbox-gl-qml.qml
[D] unknown:0 - Using Wayland-EGL
[D] onCompleted:334 - Warning: specifying an object instance for initialPage is sub-optimal - prefer to use a Component
[ERROR] {QSGRenderThread}[Style]: Failed to load sprite: HTTP status code 404
[ERROR] {QSGRenderThread}[Style]: Failed to load sprite: HTTP status code 404
[nemo@Sailfish mapbox]$


rinigus 2017-10-14 07:03

Re: Mapbox GL Native QML plugin
 
@Zeta and @tmi: thank you very much for testing!

Its indeed seems to be hard to debug this one. Since there were stability issues with earlier tests using static stdc++, I'll look into how to provide dynamic build for the plugin. Maybe it will help, although hard to tell. After testing dynamic builds (if I manage to make them), we could ask give a proper feedback to Mapbox GL developers for further tips.

Meanwhile I tested the MapboxMap using raster tile sources and it worked quite well. The small blurring that I saw on the desktop was much harder to spot on hiDPI device (you have to really look for it). While I am sure that vector tiles would be preferred, already now the MapboxMap should allow you to mix the sources as you wish.

rinigus 2017-10-14 20:06

Re: Mapbox GL Native QML plugin
 
Zeta, just in case if the shared stdc++ is better, please try to run with QML plugin from https://build.merproject.org/package...g/mapboxgl-qml

This version is compiled with shared libstdc++ with the corresponding library installed at /usr/lib/qt5/qml/MapboxMap . Now before I'll be breaking my neck and figuring out how to explain to qmlscene that the libs from that directory have a preference, please run with

Code:

LD_LIBRARY_PATH=/usr/lib/qt5/qml/MapboxMap qmlscene mapbox-gl-qml.qml
Try to see if you could make it crash with the red and full styles, please.

If its the same result as with the statically linked stdc++, I'll prefer to use that version. Then, before moving back to the statically linked plugin, please uninstall plugin first. Otherwise you'll leave libstdc++ in the plugin directory.

Zeta 2017-10-15 14:22

Re: Mapbox GL Native QML plugin
 
Quote:

Originally Posted by rinigus (Post 1536813)
Zeta, just in case if the shared stdc++ is better, please try to run with QML plugin from https://build.merproject.org/package...g/mapboxgl-qml

This version is compiled with shared libstdc++ with the corresponding library installed at /usr/lib/qt5/qml/MapboxMap . Now before I'll be breaking my neck and figuring out how to explain to qmlscene that the libs from that directory have a preference, please run with

Code:

LD_LIBRARY_PATH=/usr/lib/qt5/qml/MapboxMap qmlscene mapbox-gl-qml.qml
Try to see if you could make it crash with the red and full styles, please.

If its the same result as with the statically linked stdc++, I'll prefer to use that version. Then, before moving back to the statically linked plugin, please uninstall plugin first. Otherwise you'll leave libstdc++ in the plugin directory.

It is like the previous tests:
* Works perfectly with red map
* Crash when zooming in/moving fast the normal map

However, that must be the first useful error message I got since the start of those tests:
Code:

[nemo@Sailfish test]$ LD_LIBRARY_PATH=/usr/lib/qt5/qml/MapboxMap /usr/lib/qt5/bin/qmlscene mapbox-gl-qml.qml
[D] unknown:0 - Using Wayland-EGL
[W] unknown:0 - Could not find any zN.M subdirs!
[W] unknown:0 - Theme dir "/usr/share/themes/jolla-ambient/meegotouch/z1.0/" does not exist
[D] onCompleted:334 - Warning: specifying an object instance for initialPage is sub-optimal - prefer to use a Component
terminate called after throwing an instance of 'mbgl::gl::Error'
  what():  glDrawElements( static_cast<GLenum>(primitiveType), static_cast<GLsizei>(indexLength), GL_UNSIGNED_SHORT, reinterpret_cast<GLvoid*>(sizeof(uint16_t) * indexOffset)): Error GL_OUT_OF_MEMORY at src/mbgl/gl/context.cpp:681
Aborted

So, it looks like we got it right from the beginning : error is related to the GPU, probably because it is too weak to handle everything in its memory (GL_OUT_OF_MEMORY)...

Anyone knows a command to follow GPU memory available/used ?

rinigus 2017-10-15 14:51

Re: Mapbox GL Native QML plugin
 
Zeta, great catch!!!! At least, we could ask for advice now from Mapbox GL developers. Do you want to submit your findings into the issue https://github.com/mapbox/mapbox-gl-native/issues/10029 ?

But would be great to know how to follow GPU memory state, indeed...

Zeta 2017-10-15 15:43

Re: Mapbox GL Native QML plugin
 
Quote:

Originally Posted by rinigus (Post 1536876)
Do you want to submit your findings into the issue https://github.com/mapbox/mapbox-gl-native/issues/10029 ?

It's done !

rinigus 2017-10-15 20:18

Re: Mapbox GL Native QML plugin
 
I have extended cache database handling API to support the expected scenario:
  • cache stored in application .cache folder
  • cache size limit set by user in settings

In practice, when defining MapboxMap, its sufficient to set

Code:

    cacheDatabaseStoreSettings: true
    cacheDatabaseDefaultPath: true

and define cacheDatabaseMaximalSize during a run of an application to the value you would want to. This value will be applied on the next start of the application (cache settings are applied only on start by QMapboxGL).

API documentation has been updated accordingly.

I am planning to start working on offline support for these vector tiles via OSM Scout Server. When issues/requests/ideas will come, I'll work on them as well.

Let me know in advance if you wish to use the plugin in practice, I'll upload it into OpenRepos when needed. There is no point in uploading it too early - there were changes almost daily so far in plugin code :)


All times are GMT. The time now is 11:47.

vBulletin® Version 3.8.8