mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
466 stars 131 forks source link

Invalid argument in TileStore #1792

Closed dimitradg closed 1 year ago

dimitradg commented 1 year ago

Environment

Observed behavior and steps to reproduce

I have an activity with a Download button, and once it is clicked, offline map region is downloaded.

However, whenever I run my app I get the following crash: E/libc++abi: terminating with uncaught exception of type std::invalid_argument A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 5109 (TileStoreFileSo), pid 3898 (app).

I think I may be using wrong my mapbox tokens, but I haven't figure out the solution yet.

Anyone ideas? Thank you.

Here is the code written:

private fun download(tour:Tour) {

      //returning a MapRegion
       val region = calculateRegion(tour)

      //lateinit var  
      tileStore = TileStore.create().also {
            // Set default access token for the created tile store instance
            it.setOption(
                TileStoreOptions.MAPBOX_ACCESS_TOKEN,
                TileDataDomain.MAPS,
                Value(this.resources.getString(R.string.mapbox_key))
            )
        }

        //lateinit var
        resourceOptions = ResourceOptions.Builder()
            .applyDefaultParams(this)
            .accessToken(this.resources.getString(R.string.mapbox_key))
            .tileStoreUsageMode(TileStoreUsageMode.READ_AND_UPDATE)
            .tileStore(tileStore)
            .build()

        //lateinit var
        offlineManager = OfflineManager(resourceOptions)

        val stylePackLoadOptions = StylePackLoadOptions.Builder()
            .glyphsRasterizationMode(GlyphsRasterizationMode.IDEOGRAPHS_RASTERIZED_LOCALLY)
            .metadata(Value(STYLE_PACK_METADATA))
            //.metadata(Value(tour.id.toString()))
            .build()

        stylePackCancelable = offlineManager.loadStylePack(
            Style.OUTDOORS,
            stylePackLoadOptions,
            { progress->
                //update the download progress to UI
                Timber.i("progress: $progress")

            },
            { expected ->
                if (expected.isValue){
                    expected.value?.let{ stylePack ->
                        //style pack download finishes successfully
                        Timber.i("StylePack downloaded: $stylePack")
                    }
                }
                expected.error?.let {
                    //handle error occurred during the style pack download
                    Timber.i("StylePack error: $it")
                    Bugsnag.leaveBreadcrumb(App.User.id.toString()+" cannot download the map for $tour.id:${it.message}")
                    Snackbar.make(this.contentView!!, "Cannot download map:${it.message}.message .Please call support", 
                    Snackbar.LENGTH_LONG).show()
                }
            }
        )

        val tilesetDescriptor = offlineManager.createTilesetDescriptor(
            TilesetDescriptorOptions.Builder()
                .styleURI(Style.OUTDOORS)
                .minZoom(tour.minZoom.toInt().toByte())
                .minZoom(tour.maxZoom.toInt().toByte())
                .build()
        )

        val tileRegionLoadOptions = TileRegionLoadOptions.Builder()
            .geometry(Point.fromLngLat(region.southWest!!.longitude, region.northEast!!.latitude))
            .descriptors(listOf(tilesetDescriptor))
            .metadata(Value(TILE_REGION_METADATA))
            .acceptExpired(true)
            .networkRestriction(NetworkRestriction.NONE)
            .build()

        tilePackCancelable = tileStore.loadTileRegion(
            TILE_REGION_ID,
            tileRegionLoadOptions,
            {progress ->
                //Tile region download progress
                Timber.i("Tile region download progress: $progress")
            }
        ){expected->
            if (expected.isValue){
                //Tile region download finishes successfully
                expected.value?.let{region ->
                    Timber.i("Tile region downloaded: $region")
                }
            }
            expected.error?.let {
                //handle error occurred during the tile region download
                Timber.i("Tile region download error: $it")
                Bugsnag.leaveBreadcrumb(App.User.id.toString()+" cannot download the map for $tour.id:${it.message}")
            }
        }
    }

Expected behavior

Offline maps should be downloaded

ZiZasaurus commented 1 year ago

@dimitradg are you using the examples app itself or code from the examples app? When running the examples app I am not experiencing any crashing.

dimitradg commented 1 year ago

Hello there, I am using code from the examples app. More specifically, I have a doAsync task, and inside the uiThread I call a function with the above mentioned code.

kiryldz commented 1 year ago

Hello there, I am using code from the examples app. More specifically, I have a doAsync task, and inside the uiThread I call a function with the above mentioned code.

That comment confuses me a bit. Can you please trying https://github.com/mapbox/mapbox-maps-android/blob/main/app/src/main/java/com/mapbox/maps/testapp/examples/OfflineActivity.kt exactly as is (without doAsync etc)? If it will still crash - can you make sure that correct Mapbox token is passed here?

dimitradg commented 1 year ago

You are right, I rephrased my question so it is more understandable. As mentioned above, I am on my activity and I have a download button with an onClickListener. Once it is clicked, the above mentioned function gets called. However my app keeps crashing with the error E/libc++abi: terminating with uncaught exception of type std::invalid_argument A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 2623 (TileStoreFileSo), pid 31231 (app)

Yes I believe I am using the correct mapbox token, is the one I am already using to successfully load my maps, the android access token taken from my mapbox account.

dimitradg commented 1 year ago

I would like to post an update and close this issue:

It was my fault, I was setting minZoom two times, instead of minZoom and maxZoom:

val tilesetDescriptor = offlineManager.createTilesetDescriptor( TilesetDescriptorOptions.Builder() .styleURI(Style.OUTDOORS) .minZoom(tour.minZoom.toInt().toByte()) .minZoom(tour.maxZoom.toInt().toByte()) .build() ) Additionally, zoom range wasn't always correct.

Thank you for your time and support.