IllegalArgumentException: Unmanaged descriptor using gms.maps.model.Marker.setIcon

后端 未结 10 2040
眼角桃花
眼角桃花 2020-12-14 05:39

I have an app that use android-maps-utils and glide for marker icons.
I got an error report using Firebase crash reporting which I can\'t track in source code because

10条回答
  •  感情败类
    2020-12-14 06:13

    I have the same environment (maps-utils + custom renderer + Glide) and the same error IllegalArgumentException: Unmanaged descriptor.

    I solved the error by checking if the marker is "valid" before setting the icon, using the methods DefaultClusterRenderer.getCluster(Marker) and DefaultClusterRenderer.getClusterItem(Marker). If both return null, I don't do anything on the onResourceReady(...) method.

    In your case I would try the following change to CustomSimpleTarget:

    private class CustomSimpleTarget extends SimpleTarget {
        Sucursal sucursal;
        Marker markerToChange = null;
    
        @Override
        public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) {
    
            if (getCluster(markerToChange) != null || getClusterItem(markerToChange) != null) {
    
                mImageView.setImageDrawable(resource);
                //currentSelectedItem is the current element selected in the map (Sucursal type)
                //mIconGenerator is a: CustomIconGenerator extends IconGenerator
                if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen))
                    mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent));
                else
                    mIconGenerator.customIconBackground.useSelectionColor(false, 0);
    
                Bitmap icon = mIconGenerator.makeIcon();
    
                //GlideShortcutDrawable is a WeakReference<>(drawable)
                sucursal.setGlideShortCutDrawable(resource);
                markerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
            }
        }
    }
    

    PS.: I can reproduce the problem easily on a slow device and clearing the app cache before testing (to force Glide to load from network). Then I open the map and perform some zoom in/out before any markers load.

提交回复
热议问题