MarcusWolschon / osmeditor4android

Vespucci is a OpenStreetMap editor for Android
http://vespucci.io
Other
376 stars 83 forks source link

Crash while loading custom layer from mbtiles #1131

Closed plcp closed 4 years ago

plcp commented 4 years ago

Vespucci Version

Both 14.0.17 and 14.1.0 BETA

Download source

From Google Play Store

Behaviour/Symptoms

Going to preferences, custom layers, then loading a custom imagery from a .mbtiles file causes a crash of the application.

Expected Behaviour

Layer is loaded and no crash is encountered.

How to recreate

Load .mbtiles file causing the crash.

Crash dump submitted (no or yes + date)

Yes + 04/03/2020 between 18h10 and 18h20

Any other potentially relevant information

For more completeness, I'm quite a novice and generated the .mbtiles file using GDAL following this tutorial where 20_51_2000.tif is a georeferenced scan:

gdalwarp -t_srs EPSG:3857 -overwrite -r lanczos -te 254463.124 6245727.879 255730.47 6246685.132 20_51_2000.tif 20_51_2000-EPSG-3857.tif
gdal_translate 20_51_2000-EPSG-3857.tif 20_51_2000-EPSG-3857.mbtiles -co 'TILE_FORMAT=JPEG' -co 'QUALITY=100' -co 'TYPE=baselayer'
gdaladdo 20_51_2000-EPSG-3857.mbtiles 2 4 8 16 32 64 128 256 512 1024

Here is some gdalinfo 20_51_2000-EPSG-3857.mbtiles output:

Driver: MBTiles/MBTiles
Files: 20_51_2000-EPSG-3857.mbtiles
Size is 8489, 6412
Coordinate System is:
PROJCRS["WGS 84 / Pseudo-Mercator",
    BASEGEOGCRS["WGS 84",
        DATUM["World Geodetic System 1984",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4326]],
    CONVERSION["unnamed",
        METHOD["Popular Visualisation Pseudo Mercator",
            ID["EPSG",1024]],
        PARAMETER["Latitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["False easting",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    ID["EPSG",3857]]
Data axis to CRS axis mapping: 1,2
Origin = (254463.124000000010710,6246685.132000002078712)
Pixel Size = (0.149291070869485,-0.149291070869485)
Metadata:
  ZOOM_LEVEL=20
  name=20_51_2000-EPSG-3857
  type=baselayer
  description=20_51_2000-EPSG-3857
  version=1.1
  format=jpg
  bounds=2.28588113534001014,48.8280062178577836,2.29726577150372169,48.8336669122460876
  maxzoom=20
  minzoom=14
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  254463.124, 6246685.132) (  2d17' 9.17"E, 48d50' 1.20"N)
Lower Left  (  254463.124, 6245727.878) (  2d17' 9.17"E, 48d49'40.82"N)
Upper Right (  255730.456, 6246685.132) (  2d17'50.16"E, 48d50' 1.20"N)
Lower Right (  255730.456, 6245727.878) (  2d17'50.16"E, 48d49'40.82"N)
Center      (  255096.790, 6246206.505) (  2d17'29.66"E, 48d49'51.01"N)
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
  Overviews: 4244x3206, 2122x1603, 1061x802, 531x401, 265x200, 133x100
  Mask Flags: PER_DATASET ALPHA 
  Overviews of mask band: 4244x3206, 2122x1603, 1061x802, 531x401, 265x200, 133x100
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
  Overviews: 4244x3206, 2122x1603, 1061x802, 531x401, 265x200, 133x100
  Mask Flags: PER_DATASET ALPHA 
  Overviews of mask band: 4244x3206, 2122x1603, 1061x802, 531x401, 265x200, 133x100
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
  Overviews: 4244x3206, 2122x1603, 1061x802, 531x401, 265x200, 133x100
  Mask Flags: PER_DATASET ALPHA 
  Overviews of mask band: 4244x3206, 2122x1603, 1061x802, 531x401, 265x200, 133x100
Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
  Overviews: 4244x3206, 2122x1603, 1061x802, 531x401, 265x200, 133x100
simonpoole commented 4 years ago

Thanks for the helpful report.

This is an interesting one. The good news is that the file itself is completely OK and I actually loaded it in to Vespucci without any problems at all.

The issue seems to be with Android internal file handling aka SAF. Could you try renaming the file? And if that doesn't work moving (perhaps copying it would be better) it to the Vespucci directory? See also https://github.com/MarcusWolschon/osmeditor4android/issues/1032

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9340, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/document/raw:/storage/emulated/0/Download/20_51_2000-EPSG-3857.mbtiles flg=0x43 }} to activity {de.blau.android/de.blau.android.prefs.PrefEditor}: java.lang.NumberFormatException: For input string: "raw:/storage/emulated/0/Download/20_51_2000-EPSG-3857.mbtiles"
at android.app.ActivityThread.deliverResults(ActivityThread.java:4506)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4548)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1916)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NumberFormatException: For input string: "raw:/storage/emulated/0/Download/20_51_2000-EPSG-3857.mbtiles"
at java.lang.Long.parseLong(Long.java:594)
at java.lang.Long.valueOf(Long.java:808)
at de.blau.android.util.aj.a(SelectFile.java:239)
at de.blau.android.util.q.a(FileUtil.java:122)
at de.blau.android.resources.TileLayerDialog$2$1.a(TileLayerDialog.java:173)
at de.blau.android.util.aj.a(SelectFile.java:180)
at de.blau.android.prefs.f.onActivityResult(PrefEditorActivity.java:80)
at android.app.Activity.dispatchActivityResult(Activity.java:7476)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4499)
... 11 more

Screenshot_1583347146

Stackoverflow finds https://stackoverflow.com/questions/51136671/oreo-documentscontract-getdocumentiduri-returns-path-instead-of-long

simonpoole commented 4 years ago

Potentially fixed in https://github.com/MarcusWolschon/osmeditor4android/commit/cd8736fd704546aa360047edd54b034597f82bdb

If you are willing to try a debug build (will require deinstalling the google play version) I'll upload one for you to test.

plcp commented 4 years ago

Renaming the file reproduce the problem, moving the file from /sdcard/Downloads to the existing /sdcard/Vespucci solves the problem. I'm open to try a debug build if this can help you to improve Vespucci.

Nonetheless, thank you for fixing my problem !

simonpoole commented 4 years ago

The problem is that I can't recreate the problem here, so I don't really have a way of knowing if I fixed the underlying issue or not. How did you download/load the mbtiles file on to your device?

plcp commented 4 years ago

I've uploaded the file to a personal hosting service and downloaded it via HTTP using firefox then tried to open it in Vespucci. I've subsequently tried with other files generated in different ways and all were failing while they were in the Downloads directory.

Cutting & pasting them into the Vespucci directory created by the application fixes the problem, and in the same manner cutting & pasting them into the Movies directory works too. Trying several other directories works too, however putting it back inside the Downloads directory reproduce the issue.

I'm available to install any build you'll provide me and try to import the file from the Downloads directory.

(I can freely remove/reinstall the application several times without suffering data loss, I already backuped ongoing work)

simonpoole commented 4 years ago

"Firefox" was the missing bit of information, seems as if it stores files differently in the Downloads directory than Chrome/the standard browser (differently and undocumented). In any case with FF I can recreate the issue and confirm that the fix actually works.

Thanks for the support.