maplibre / maplibre-native

MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
https://maplibre.org
BSD 2-Clause "Simplified" License
1.03k stars 299 forks source link

java.lang.Error: bounds must be an array with left, bottom, top, and right values #820

Closed NiKoTron closed 1 year ago

NiKoTron commented 1 year ago

Describe the bug Got a crash while creating a RasterSource object with TileSet with bounds.

java.lang.Error: bounds must be an array with left, bottom, top, and right values
        at com.mapbox.mapboxsdk.style.sources.RasterSource.initialize(Native Method)
        at com.mapbox.mapboxsdk.style.sources.RasterSource.<init>(RasterSource.kt:136)

To Reproduce Steps to reproduce the behavior:

  1. Populate TileSet's bounds with float array
  2. Create RasterSource with it TileSet
  3. See error - java.lang.Error: bounds must be an array with left, bottom, top, and right values

Expected behavior A clear and concise description of what you expected to happen.

Platform information (please complete the following information):

Additional context It reproduced only with android library v10.0.0 There's no exception on earlier versions

louwers commented 1 year ago

@NiKoTron This might be due to a file that was migrated to Kotlin.

Do you happen to have a code snippet that reproduces the error? That would be helpful.

NiKoTron commented 1 year ago

@louwers Yep, I guess it's relates to kotlin to native interportability of floats or smth.

There's a function with minimum reproducible steps

    fun minimumReproducibleExample(){
        val tiles = arrayOf("https://api.maptiler.com/tiles/satellite-v2/{z}/{x}/{y}@2x.jpg?key=your_key")
        val tileSet = TileSet("2.1.0", *tiles)

        //set bounds here
        val bounds = floatArrayOf(-180.0f, -85.05113f, 180.0f, 85.05113f)
        tileSet.setBounds(*bounds) // or like tileSet.setBounds(-180.0f, -85.05113f, 180.0f, 85.05113f) doesn't matter

        //trying to create source
        RasterSource("source_id", tileSet) // <- Crash here
        //java.lang.Error: bounds must be an array with left, bottom, top, and right values
        //        at com.mapbox.mapboxsdk.style.sources.RasterSource.initialize(Native Method)
        //        at com.mapbox.mapboxsdk.style.sources.RasterSource.<init>(RasterSource.kt:125)
    }
louwers commented 1 year ago

Thanks

The root cause seems to be that Kotlin's FloatArray is not recognized as an array anymore.

https://github.com/maplibre/maplibre-gl-native/blob/20aefdc780da192997957f41866303496480c164/platform/android/MapboxGLAndroidSDK/src/cpp/style/value.cpp#L22

I created a test with a reproduction

https://github.com/louwers/maplibre-gl-native/commit/0d8d4f1bed88d1756dda8c51ab45344b9da1ea82

We can either go back to using Float[] or adopt the C++ JNI interface so that it can handle FloatArray. @artakka what do you think is best?

artakka commented 1 year ago

@louwers Will have a look