My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 9765: Bug: setIcon(With resource id) on marker outside view makes the marker white.
140 people starred this issue and may be notified of changes. Back to list
Status:  Accepted
Owner:  ----


Sign in to add a comment
 
Reported by [email protected], May 13, 2016
Moving around the marker and changing the marker icon makes the marker white after a while. It seems to work in the beginning, but after 5-10 seconds (sometimes immediately) the markers starts to appear white when the markers are outside the camera and then moved them inside the camera again.

This seem to have started to happen with a new Google Play services update around April 22nd.

I've attached a template from the Android Studio maps template with and with marker moving around a lot and changing icons.

Steps to Reproduce:
1.  Load and build github project https://github.com/SimonSikstrom/google-maps-api-v2-white-markers-bug
2. start the app and see how the markers become white after a short time.


- Device (and version of Android) you have verified this issue on: Nexus 5, Android Version 6.0.1
- Google Play Services client library version: com.google.android.gms:play-services:8.4.0
- Google Play Services version on the device: 9.0.83 (438-121911109)
- Android SDK Version: 23
- Was this working correctly on a previous version of Google Play Services? YES.
- which client library and SDK version? Don't know, before a google play services April release.

Br
Screenshot_20160513-201924.png
1.8 MB   View   Download
May 13, 2016
#1 [email protected]
Occurs when having Google Play Services version 8.9.16 as well
May 13, 2016
Project Member #2 [email protected]
Thanks for the report! Have you seen this on any other devices so far?

#1 - Did you see the same behavior (setIcon and white markers if moved off screen) on a device running Google Play Services 8.9.16 as well? 

We will take a look.
Status: Accepted
Labels: Internal-28768125
May 13, 2016
#3 [email protected]
A user has reported this behavior in 8.9.16, yes.
Seems to be the updated GP Services version that causes this strange behaviour, not a specific brand or device.
May 14, 2016
#6 [email protected]
On GP Services 8.7.01, Android 5.1 everything is fine. On GP Services 9.0.82, Android 4.3 white squares occur in place of markers after zooming and panning the map. 
Also sometimes other graphics are displayed in place of markers. See red arrow on attached screen.
Screenshot_2016-05-14-18-03-05.png
539 KB   View   Download
May 14, 2016
#7 [email protected]
Markers were working fine even on 8.7.03, but latest update 9.0.78 showing white square box for some markers. Big issue now.
May 16, 2016
#8 [email protected]
Since I cannot be sure how long it will take for Google to solve this I'll have to use Bitmaps instead of Resource Id for now:

For everyone interested in a possible workaround:

change
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.drawableid));

to
marker.setIcon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.drawableid))); //could affect general memory consumption tho(?), I haven't tested with more than the app reported with in the issue.

I don't get the same problem after doing this.
May 16, 2016
#9 [email protected]
The proposed BitmapDescriptorFactory workaround has no effect for me.  I did find that removing all of my calls to Marker.remove() caused the problem to stop (of course, performance quickly became unacceptable).
May 16, 2016
#10 [email protected]
We can repro this bug which causes certain marker icons to render as white patches. Your app may be affected if an icon bitmap is shared among multiple markers, although the issue only manifests in specific usage scenarios.

In the short term, we'd recommend the workaround in #8 -- use a unique Bitmap object for each marker:

marker.setIcon(BitmapDescriptorFactory.fromBitmap(
	BitmapFactory.decodeResource(getResources(), R.drawable.drawableid)));

and

new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(
	BitmapFactory.decodeResource(getResources(), R.drawable.drawableid)));

Creating a BitmapDescriptor once and reusing it won’t be sufficient. E.g. if you’re doing:

BitmapDescriptor bd = ...;
marker1.setIcon(bd);
marker2.setIcon(bd);

...then the workaround would be:

marker1.setIcon(BitmapDescriptorFactory.fromBitmap(
	BitmapFactory.decodeResource(getResources(), R.drawable.drawableid)));
marker2.setIcon(BitmapDescriptorFactory.fromBitmap(
	BitmapFactory.decodeResource(getResources(), R.drawable.drawableid)));

Please note that, if your app uses a lot of markers, this workaround could possibly result in higher memory consumption. Also, unfortunately the workaround doesn’t apply when the default icon is used via BitmapDescriptorFactory.defaultMarker().

May 17, 2016
#11 [email protected]
We use pins and clusters quite extensively - 500+ per country and we'll probably start getting bad reviews from our customers soon :(

I tried the workaround mentioned in #8 and #10, but it worked only for pins - not for default clusters (e.g. 20+ and so on).
May 17, 2016
#12 [email protected]
How to create marker with ViewCustom (.xml) or bitmap :(
May 17, 2016
#13 [email protected]
This workaround is pretty bad for generated markers.
May 17, 2016
#14 [email protected]
This is a pretty bad issue, it's affecting our app's usability considerably.

Can we get a rush on a fix for this please?
May 17, 2016
#15 [email protected]
Thankfully this doesn't seem to affect our application - https://github.com/OneBusAway/onebusaway-android.

Here's the code that generates the bus stop icons:
https://github.com/OneBusAway/onebusaway-android/blob/master/onebusaway-android/src/google/java/org/onebusaway/android/map/googlemapsv2/StopOverlay.java#L175

This likely works for us because we're not loading a bitmap from an image resource (PNG), but instead are generating it from an XML resource and drawing via Canvas.  Simplified version of the code follows in case it's helpful to anyone.

We're re-using Bitmaps stored in an array - we draw arrows showing direction of bus service, so NUM_DIRECTIONS = 9 (each direction + no direction - 9 Bitmaps total):

    private static Bitmap[] bus_stop_icons = new Bitmap[NUM_DIRECTIONS];

For each Bitmap, we create a new Bitmap in memory and create a Canvas object:

    Bitmap bus_stop_icons[0] = Bitmap.createBitmap(mPx, mPx, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bus_stop_icons[0]);

Then, we load a drawable from an XML resource and set the dimensions to the XML drawable and draw the shape (adding the arrow of direction, if included):

    Drawable shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
    shape.setBounds(0, 0, bus_stop_icons[0].getWidth(), bus_stop_icons[0].getHeight());
    shape.draw(c);

R.drawable.map_stop_icon is a <layer-list>:
https://github.com/OneBusAway/onebusaway-android/blob/master/onebusaway-android/src/main/res/drawable/map_stop_icon.xml

And then we create the BitmapDescriptor for each marker from the array of Bitmaps:

    Marker m = mMap.addMarker(new MarkerOptions()
        .position(stop.getLocation())
        .icon(BitmapDescriptorFactory.fromBitmap(bus_stop_icons[0]))

Not sure if this helps anyone, but might be worth investigating if other above workarounds don't work, and you don't need to load a PNG, or could replicate the PNG in XML drawable.
May 17, 2016
#17 [email protected]
For whatever reason I implemented an internal markers cache to share bitmap descriptors and noticed this issue as well. Removed the cache -- now it works fine. However I was getting the issue for com.google.android.gms:play-services:6.5.87:aar
May 17, 2016
#19 [email protected]
We are also facing the issue, we have play services 9 and sdk 8.4
May 18, 2016
#20 [email protected]
I am facing also the same issue. nexus huawei 6p with latest updates!
May 18, 2016
#21 [email protected]
The same issue here. But the white squares appear for cluster bubble as well. Google Play services 9.0.83
May 18, 2016
#23 [email protected]
Same issue happening for me as well on 2 devices:
1. Nexus 5X
OS - 6.0.1
Google Play Services - 9.0.83
Dependencies in build.gradle file:
'com.google.android.gms:play-services-maps:9.0.0'
'com.google.maps.android:android-maps-utils:0.4+'

2. Samsung Galaxy S5
OS - 5.0
Google Play Services - 9.0.83
Dependencies in build.gradle file:
'com.google.android.gms:play-services-maps:9.0.0'
'com.google.maps.android:android-maps-utils:0.4+'

Issue I am facing:
When I zoom in and zoom out (multiple times) on a cluster, white squares start showing up instead of my custom marker icons & default cluster icons.
And yes, I am instantiating the BitmapDescriptor just once and then using that instance for around 200 markers on the map.
May 20, 2016
#24 [email protected]
The issue stopped occurring on my devices (Nexus 6P and Samsung G531F) after disabling clustering - I've added:

    @Override
    protected boolean shouldRenderAsCluster(Cluster<StationClusterItem> cluster) {
      // Never create clusters - display markers only
      return false;
    }

in our subclass of DefaultClusterRenderer. It is not a solution to the problem, but we wanted to remove clustering from our app anyway.
May 20, 2016
#25 [email protected]
Same issue: starting on Google Play Services 9.0.83 when using map zoom in/out, white boxes are displayed where markers should be rendered. We use 'maps-utils' for marker clustering, but this behavior is happening whether or not marker clustering is actually in effect.

    'com.google.android.gms:play-services-maps:8.4.0'
    'com.google.maps.android:android-maps-utils:0.4.1'

Screenshot_20160520-160517.png
221 KB   View   Download
Screenshot_20160520-160540.png
332 KB   View   Download
May 20, 2016
#26 [email protected]
I tried the suggestion to disable cluster rendering but it did not fix the issues for me:

>    // DefaultClusterRenderer
>    @Override
>    protected boolean shouldRenderAsCluster(Cluster<StationClusterItem> cluster) {
>      // Never create clusters - display markers only
>      return false;
>    }


May 20, 2016
#27 [email protected]
The suggestion from comment #10 did work for me, but I am also concerned about the memory consumption and performance impact. Will use it as a temporary workaround.

There is a discussion on this topic on GitHub for android-maps-utils:
https://github.com/googlemaps/android-maps-utils/issues/276



May 21, 2016
#28 bishop87
I tried to post a full code with my workaround implementation:
https://github.com/googlemaps/android-maps-utils/issues/276#issuecomment-220816216

In short, I removed the usage of SparseArray object on "onBeforeClusterRendered" method, drawing every cluster with its own bitmap.
MyMapRender.java
4.9 KB   View   Download
May 23, 2016
#29 [email protected]
Any rough ETA on when we might expect a fix for this issue? We are starting to get negative feedback from customers 
May 24, 2016
#30 [email protected]
Same issue - white rectangular patches while clustering.

But clustering is an important feature in our app. So disabling doesn’t help me.

Is there any workaround for this or do we need to wait for the next update?


May 25, 2016
#31 [email protected]
Workaround works in most cases, but I hope that "breaking all maps apps" is not considered acceptable and is going to be fixed soon on Google's side.
May 25, 2016
#32 [email protected]
We have the same issue. Re-set icons sometimes helps, but not in all cases.
May 25, 2016
#33 [email protected]
Some feedback from those looking into this issue would be greatly appreciated here since people need to know if they should take the time to investigate/implement their own work-arounds or if that will be wasted effort because a fix is forthcoming from Google.
May 26, 2016
#34 [email protected]
Any updates on an actual fix for this?
May 26, 2016
#35 [email protected]
We have frustrated customers on the phone and we are not happy with not knowing anything about when the issue will be fixed. 
Please assure us that a solution is in the works and provide an estimated date for it.
May 26, 2016
#36 diegosiuniube
Please, somebody have fixed this?
6fae1efa-1e63-11e6-99c9-d5905849289a.png
535 KB   View   Download
May 26, 2016
#37 [email protected]
There is a workaround, while waiting for a real fix.
I have noticed that you must use a unique BitmapDescriptor object for each marker (whitout reusing it), but can reuse a common Bitmap object.

Example:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.drawableid)); --> REUSABLE

marker1.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
marker2.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
marker3.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));

I think this solution involves lower memory comsuption than google's one (comment #10), as it avoids re-instantiating the Bitmap object for each marker..

I have tested it on old devices with poor performance and it wasn't too laggy. 
May 26, 2016
#38 [email protected]
tried #37. It seems working fine now. previously I was trying to cache those BitmapDescriptor which could be reused. Now I changed to cache Bitmap instead. 
May 27, 2016
#39 [email protected]
#37 works fine. We also used the same workaround but it increased a memory consumption and make app too laggy because of GC collecting bitmap descriptors of removed markers (since we don't cache them now). Google, why do you keep silence?
May 28, 2016
#40 [email protected]
Same problem here - all test devices from JB to M.  Just using default markers no clustering.  Started with GPS 9.0.83 update.  Also causes crash on one of my KitKat dev devices (Vodafone smart 4 turbo) on every boot "FATAL EXCEPTION: main"
Process: com.google.android.gms.persistent"
Java.lang.noclassdeffounderror: fmo
At com.google.android.gms.backup.backuptransportchimeraservice.<init>(source file:144)
Etc

"Unfortunately Google play services has stopped"

The error occurs again after pressing ok
May 31 (4 days ago)
#41 [email protected]
Still no news on this? Negative reviews (about bad performance due to these workarounds) are coming...
Jun 1 (3 days ago)
#42 [email protected]
Having the same issue
Jun 1 (3 days ago)
#43 [email protected]
I have the same issue
Screenshot_2016-05-26-14-11-39.png
260 KB   View   Download
Jun 1 (3 days ago)
#44 [email protected]
Im having the issue as well and the number of markers I have make the workaround a bad solution for the problem.
Jun 1 (3 days ago)
#45 [email protected]
Also having same issue. Was working before. Reverting google maps on the device removes the issue.

Is their a ETA/Schedule for this?

Implementing workaround is not easy for us, and there is a lot of pins we use. Recycling is important for our map design as we create bitmaps on the fly, to not re-use will severely hurt performance.

If we don't do anything, people will compain about white squares.
If we do something, they'll be complaining about performance and memory issues.

Persronally, I'll take white squares instead of OOM errors, but I'd like to not have to choose.
Jun 2 (2 days ago)
#48 [email protected]
This worked for me: I re-draw a drawable to bitmap!

* Code:

private Bitmap drawableToBitmap(int drawableId) {
        Drawable mDrawable = cContext.getResources().getDrawable(drawableId);
        Bitmap mResultBitmap = null;

        if (mDrawable instanceof BitmapDrawable) {
            BitmapDrawable mBitmapDrawable = (BitmapDrawable) mDrawable;
            
            if (mBitmapDrawable.getBitmap() != null) {
                return mBitmapDrawable.getBitmap();
            }
        }

        if (mDrawable.getIntrinsicWidth() <= 0 || mDrawable.getIntrinsicHeight() <= 0) {
            mResultBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        } else {
            mResultBitmap = Bitmap.createBitmap(mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        }

        Canvas mCanvas = new Canvas(mResultBitmap);
        mDrawable.setBounds(0, 0, mCanvas.getWidth(), mCanvas.getHeight());
        mDrawable.draw(mCanvas);

        return mResultBitmap;
    }

* Using: mMarkerOptions.icon(BitmapDescriptorFactory
                        .fromBitmap(drawableToBitmap(R.drawable.the_marker_icon)));

Hope this help someone!
Jun 2 (2 days ago)
#49 [email protected]
Replace your LayerDrawable makeClusterBackground() method with 

 private LayerDrawable makeClusterBackground(int color) {
        ShapeDrawable mColoredCircleBackground = new ShapeDrawable(new OvalShape());
        mColoredCircleBackground.getPaint().setColor(color);
        ShapeDrawable outline = new ShapeDrawable(new OvalShape());
        outline.getPaint().setColor(Color.TRANSPARENT);
        LayerDrawable background = new LayerDrawable(new Drawable[]{outline, mColoredCircleBackground});
        int strokeWidth = (int) (mDensity * 3.0F);
        background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
        return background;
    }


and Replace onBeforeClusterRendered  with this

protected void onBeforeClusterRendered(Cluster<T> cluster, MarkerOptions markerOptions) {
    	int clusterSize = getBucket(cluster);

        mIconGenerator.setBackground(makeClusterBackground(getColor(clusterSize)));
	BitmapDescriptor descriptor = BitmapDescriptorFactory.fromBitmap(mIconGenerator.makeIcon(getClusterText(clusterSize)));
        markerOptions.icon(descriptor);
    }

now you can set your own marker icon in markeroption like

 markerOptions.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.location_detail);));

Jun 2 (2 days ago)
#50 [email protected]
#8 help me, but this solution disable icon cache and maybe cause OutOfMemory, when many clusters on map.
Jun 2 (2 days ago)
#51 [email protected]
This is not just a problem with cluster icons but with marker icons in general. 

Creating marker icons from bitmap (BitmapDescriptorFactory.fromBitmap()) will cause OutOfMemory error sooner or later, so this is not an option. 
To avoid OutOfMemory errors marker icons need be created from resource (BitmapDescriptorFactory.fromResource()).

In our app we are creating icons using a unique Bitmap object for each marker already (as #10 proposed) and markers showing as white squares:

.icon(BitmapDescriptorFactory.fromResource(<resourceId>))

This bug is a big issue and users are already complaining.
Yesterday (36 hours ago)
#52 [email protected]
This is extremely nasty bug. You can get also "other colors" than white. I had my own bug and my layout was transparent. I clicked marker on map and it opened this transparent layout as it should, then I notice that invalid markers were not white but "copy some map portion on it" ...

Google please correct this erros asap or tell where togo back as it was working normally..
Sign in to add a comment

Powered by Google Project Hosting