Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KmlRenderer - FATAL EXCEPTION: width and height must be > 0 #863

Open
alexdiaz2 opened this issue Apr 24, 2021 · 1 comment
Open

KmlRenderer - FATAL EXCEPTION: width and height must be > 0 #863

alexdiaz2 opened this issue Apr 24, 2021 · 1 comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@alexdiaz2
Copy link

Please be sure to include as much information as possible:

Summary

When trying to create a KmlLayer, a "FATAL EXCEPTION" occurs when trying to "createBitmap", the error is "width and height must be > 0"

Expected behavior

Prevent the "FATAL EXCEPTION" and get a warning or throw an exception

Observed behavior

When trying to create a KmlLayer with an Kml file that has images, for some Kml files it throws the fatal exception indicating that the width and height must be > 0 instead of throwing an exception, the KmlRenderer.scaleBitmap is not validating the width and height before calling the Bitmap.createBitmap libray.

Environment details

  1. Device make and model, or emulator details: Device -> Samsung SM-G9650, Emulator -> Pixel 2 API 26 x86
  2. Android version: Device -> 10, Emulator -> 8
  3. Library version and other environment information:
    com.google.maps.android:android-maps-utils:2.2.2
    com.google.maps.android.data.kml.KmlLayer
    KmlRenderer

Steps to reproduce

If you can reproduce using the demo app in the project, it helps us troubleshoot faster.

  1. Using the following kmz file: http://maps.continentalshelf.org/kmz/JODC_Trackline.kmz
  2. Uncompress it and then send it as a ByteArrayInputSream to KmlLayer: KmlLayer kmlLayer = new KmlLayer(mMap, new ByteArrayInputStream(kmz.getBytes()), this);
  3. Call addLayerToMap function: kmlLayer.addLayerToMap();
  4. The app will crash with a FATAL EXCEPTION

Code example

                    InputStream inputStream = new FileInputStream(kmlFile); //context.openFileInput(fil);
                    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                    String receiveString;
                    StringBuilder stringBuilder = new StringBuilder();

                    while ((receiveString = bufferedReader.readLine()) != null) {
                        stringBuilder.append(receiveString);
                    }

                    inputStream.close();
                    String kmz = stringBuilder.toString();
                    KmlLayer kmlLayer = new KmlLayer(mMap, new ByteArrayInputStream(kmz.getBytes()), this);
                    kmlLayer.addLayerToMap();

Stack trace

FATAL EXCEPTION: main
    Process: com.test, PID: 28302
    java.lang.IllegalArgumentException: width and height must be > 0
        at android.graphics.Bitmap.createBitmap(Bitmap.java:1148)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:987)
        at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:842)
        at com.google.maps.android.data.Renderer.scaleIcon(Renderer.java:401)
        at com.google.maps.android.data.Renderer.getCachedMarkerImage(Renderer.java:366)
        at com.google.maps.android.data.kml.KmlRenderer.scaleBitmap(KmlRenderer.java:407)
        at com.google.maps.android.data.kml.KmlRenderer.addIconToMarker(KmlRenderer.java:394)
        at com.google.maps.android.data.kml.KmlRenderer.addIconToGeometry(KmlRenderer.java:353)
        at com.google.maps.android.data.kml.KmlRenderer.addIconToMultiGeometry(KmlRenderer.java:374)
        at com.google.maps.android.data.kml.KmlRenderer.addIconToGeometry(KmlRenderer.java:355)
        at com.google.maps.android.data.kml.KmlRenderer.addIconToMarkers(KmlRenderer.java:335)
        at com.google.maps.android.data.kml.KmlRenderer.addContainerGroupIconsToMarkers(KmlRenderer.java:420)
        at com.google.maps.android.data.kml.KmlRenderer.addContainerGroupIconsToMarkers(KmlRenderer.java:422)
        at com.google.maps.android.data.kml.KmlRenderer.access$600(KmlRenderer.java:58)
        at com.google.maps.android.data.kml.KmlRenderer$MarkerIconImageDownload.onPostExecute(KmlRenderer.java:562)
        at com.google.maps.android.data.kml.KmlRenderer$MarkerIconImageDownload.onPostExecute(KmlRenderer.java:517)
        at android.os.AsyncTask.finish(AsyncTask.java:755)
        at android.os.AsyncTask.access$900(AsyncTask.java:192)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

Thanks!

@alexdiaz2 alexdiaz2 added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 24, 2021
@barbeau
Copy link
Collaborator

barbeau commented Apr 27, 2021

@alexdiaz2 Thanks for the sample data! I'll try to take a look at this soon.

@kikoso kikoso added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed triage me I really want to be triaged. labels Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants