32

I am currently developing an android application using google maps api and I sometimes get a weird crash (in my opinion) for no ovious reason. Here's the crash log :

12-02 16:38:57.071  20796-21137/com.appsolute.ParkYoo E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 4623
    Process: com.appsolute.ParkYoo, PID: 20796
    java.lang.NullPointerException: Attempt to get length of null array
            at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:399)
            at java.nio.ByteBufferAsShortBuffer.put(ByteBufferAsShortBuffer.java:159)
            at com.google.maps.api.android.lib6.gmm6.o.c.a.d.d(Unknown Source)
            at com.google.maps.api.android.lib6.gmm6.o.c.a.d.a(Unknown Source)
            at com.google.maps.api.android.lib6.gmm6.o.a.a(Unknown Source)
            at com.google.maps.api.android.lib6.gmm6.o.c.b(Unknown Source)
            at com.google.maps.api.android.lib6.gmm6.o.c.a(Unknown Source)
            at com.google.maps.api.android.lib6.gmm6.o.l.a(Unknown Source)
            at com.google.maps.api.android.lib6.gmm6.o.l.b(Unknown Source)
            at com.google.maps.api.android.lib6.gmm6.o.cw.k(Unknown Source)
            at com.google.maps.api.android.lib6.gmm6.o.cw.run(Unknown Source)

As you can see, the crash happens in google api but the code has been obfuscated so I don't have more infos about that except on the 2 first lines :

final void put(short[] src, int srcOffset, int shortCount) {
    checkIsAccessible();
    int byteCount = checkPutBounds(SizeOf.SHORT, src.length, srcOffset, shortCount); // here is the error
    this.block.pokeShortArray(offset + position, src, srcOffset, shortCount, order.needsSwap);
    position += byteCount;
  }

@Override
    public ShortBuffer put(short[] src, int srcOffset, int shortCount) {
        byteBuffer.limit(limit * SizeOf.SHORT);
        byteBuffer.position(position * SizeOf.SHORT);
        if (byteBuffer instanceof DirectByteBuffer) {
            ((DirectByteBuffer) byteBuffer).put(src, srcOffset, shortCount);
        } else {
            ((ByteArrayBuffer) byteBuffer).put(src, srcOffset, shortCount);
        }
        this.position += shortCount;
        return this;
    }

Has anyone already encountered this bug ? What am I doing wrong ? If anybody has an insight concerning this issue, I'll be pleased to discuss it.

Thanks !

user3476114
  • 634
  • 1
  • 7
  • 17
  • well how about showing what you are doing in your code – tyczj Dec 02 '14 at 15:56
  • 2
    Hi and thanks for your answer. As I said, this doesn't happen in my code but in the maps lib code. Anyway I'm eager to show you my code but what do you want to see ? At the moment I set up 2 GoogleMaps in tabbed activity. – user3476114 Dec 02 '14 at 16:18
  • I'm getting the same crash, but it wasn't happening before. Are you running your app on Lollipop? I'm thinking it has to do with it – wmora Dec 04 '14 at 14:49
  • Hi wmora. Yes my apps runs on Lollipop but it also happened on my nexus 4 which still is on KitKat (4.4.4) and running with dalvik runtime. Still a mystery to me... – user3476114 Dec 05 '14 at 09:28
  • reported this issue in Crashlytics for my app for both 5.1 & 6.0.1 on Vivo device and that too occasionally. And I have been never able to reproduce the issue – Shirish Herwade Mar 23 '18 at 06:32

3 Answers3

17

You're likely running more than one map fragment. See my writeup on this fatal bug currently haunting the Google Maps library, concerning multiple map fragments - and how I found a workaround.

https://medium.com/aphex-cx/the-google-maps-api-is-broken-on-android-5-heres-a-workaround-for-multiple-map-fragments-6a95655c92fd

Google is currently working on the case and is prioritizing it for the next release of Google Play Services!

lewkka
  • 1,019
  • 15
  • 25
Aphex
  • 7,390
  • 5
  • 33
  • 54
1

Updated com.google.gms:google-services version in build.gradle (android level) from https://developers.google.com/android/guides/google-services-plugin

in my case, it is com.google.gms:google-services:4.3.14

Implemented a workaround from https://github.com/flutter/flutter/issues/105965#issuecomment-1224473127

This seems to work for me.

Abdul Bari
  • 11
  • 1
  • But people complain that the latest renderer is too unstable, although such renderer will improve over time. The current state is really undesirable. – Martin Braun Nov 29 '22 at 11:09
0

If its happening with flutter build related to google maps the

  1. Be on flutter 3.2 or below versions
  2. https://github.com/flutter/flutter/issues/105965#issuecomment-1224473127 Use this code block and run the app
  3. Check if you are getting "The latest version of the renderer is used" Log

Note : Delete the build folder in project before running the app

If you want sample code how to check it

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class AltScreen extends StatelessWidget {
  const AltScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Alt screen'),
      ),
      body: Center(
        child: ElevatedButton(
          child: const Text('Push map'),
          onPressed: () => Navigator.of(context, rootNavigator: true).push(
            MaterialPageRoute(
              builder: (ctx) => Scaffold(
                appBar: AppBar(
                  actions: [
                    IconButton(
                      onPressed: Navigator.of(ctx, rootNavigator: true).pop,
                      icon: const Icon(Icons.close),
                    ),
                  ],
                ),
                body: const GoogleMap(
                  initialCameraPosition: CameraPosition(
                    target: LatLng(41.9, 12.5),
                    zoom: 17,
                  ),
                  compassEnabled: false,
                  myLocationButtonEnabled: false,
                  myLocationEnabled: false,
                  scrollGesturesEnabled: true,
                  zoomGesturesEnabled: true,
                  rotateGesturesEnabled: false,
                  zoomControlsEnabled: false,
                  mapToolbarEnabled: false,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}