weixin_39608478
2021-01-08 11:57 阅读 0

"Released unknown imageData reference"

I am doing the clustering dynamically to get an acceptable performance:

 java
 private class DynamicallyAddMarkerTask extends AsyncTask {

        protected void onPostExecute(Object o) {
            super.onPostExecute(o);
            clusterManager.cluster();
        }


        protected Object doInBackground(Object[] objects) {
            LatLngBounds bounds = (LatLngBounds) objects[0];
            clusterManager.clearItems();

            for (LoyaltyOutlet currentMarker : sortedAndFilteredOutlets) {
                if (bounds.contains(currentMarker.getPosition())) {
                    clusterManager.addItem(currentMarker);
                }
            }

            return null;
        }
    }

This is triggered in a OnCameraChangeListener but unfortunately this makes the lib crash my app now and then. Do you think it will possible to fix this issue in the lib by for example just ignoring the exception?

Crash stack trace:

 java
 java.lang.IllegalArgumentException: Released unknown imageData reference
            at com.google.common.base.j.a(Unknown Source)
            at com.google.maps.api.android.lib6.impl.f.c(Unknown Source)
            at com.google.maps.api.android.lib6.impl.ap.a(Unknown Source)
            at com.google.maps.api.android.lib6.impl.ap.remove(Unknown Source)
            at com.google.android.gms.maps.model.internal.IMarkerDelegate$Stub.onTransact(IMarkerDelegate.java:51)
            at android.os.Binder.transact(Binder.java:347)
            at com.google.android.gms.maps.model.internal.zzi$zza$zza.remove(Unknown Source)
            at com.google.android.gms.maps.model.Marker.remove(Unknown Source)
            at com.google.maps.android.MarkerManager$Collection.remove(MarkerManager.java:163)
            at com.google.maps.android.MarkerManager.remove(MarkerManager.java:140)
            at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.removeMarker(DefaultClusterRenderer.java:637)
            at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.performNextTask(DefaultClusterRenderer.java:628)
            at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.handleMessage(DefaultClusterRenderer.java:596)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at dalvik.system.NativeStart.main(Native Method)

该提问来源于开源项目:googlemaps/android-maps-utils

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

18条回答 默认 最新

  • weixin_39955421 weixin_39955421 2021-01-08 11:57

    I have to second this issue, looks like synchronization error on clearItems call

    点赞 评论 复制链接分享
  • weixin_39849888 weixin_39849888 2021-01-08 11:57

    I too am struggling with a similar issue. I think the problem comes from your sortedAndFilteredOutlets variable, which retails references to markers that have been removed from the map. They exist outside the map because you keep a reference to them, but otherwise they no longer exist.

    点赞 评论 复制链接分享
  • weixin_39854288 weixin_39854288 2021-01-08 11:57

    Hi all, any idea how to fix it or at least avoid it? I'm struggling to find out why is this happening on my code. It happens every few times you add or clean markers on the map.

    点赞 评论 复制链接分享
  • weixin_39849888 weixin_39849888 2021-01-08 11:57

    The best way I found was to never clear the markers straight from the map itself but from the cluster manager.

    点赞 评论 复制链接分享
  • weixin_39854288 weixin_39854288 2021-01-08 11:57

    Thanks for the tip.

    This is how I have it now:

    
            mClusterManager.clearItems();
            mClusterManager.addItems(mMapVenueItems);
            mClusterManager.cluster();
    

    I'm not really removing them from the map as far as I can tell, just using the cluster manager for that. I do have a list of ClusterItems on the activity, not sure if that could be the source of the problem when manipulating that List.

    点赞 评论 复制链接分享
  • weixin_39849888 weixin_39849888 2021-01-08 11:57

    You must release all copies of markers you don't have on the map when you clear the items. Like if you keep a list of them, clear it too.

    点赞 评论 复制链接分享
  • weixin_39608478 weixin_39608478 2021-01-08 11:57

    I ended up making my own "DefaultClusterRenderer" where the only diffenrence was a lot of try..catch around the areas which made my app crash. Not pretty but gets the job done...

    点赞 评论 复制链接分享
  • weixin_39854288 weixin_39854288 2021-01-08 11:57

    I'm still looking into this so I will try that option as well. It's really annoying the random crashes.

    点赞 评论 复制链接分享
  • weixin_39854288 weixin_39854288 2021-01-08 11:57

    I've just done that and it works fine, I'm not stooping the error just catching it which doesn't seem to cause any further issues. Good enough :)

    点赞 评论 复制链接分享
  • weixin_39948309 weixin_39948309 2021-01-08 11:57

    Had the same issue for marker.setIcon() in an asyncTask. I didn't found any solution yet.. And I'm following just catching the error.

    If anyone found the solution. please share it here.. I really need it...

    点赞 评论 复制链接分享
  • weixin_39519619 weixin_39519619 2021-01-08 11:57

    I only clear items from ClusterManager, never from the map, and issue is still present. Occurs randomly, usually never on emulator, but on a real device

    点赞 评论 复制链接分享
  • weixin_39519619 weixin_39519619 2021-01-08 11:57

    Have added clusterManager.clear() in onStop, looks like that resolved the issue - probably without that onStop tries to clear items from the map before cluster manager and that results in this bug.

    I've checked Google Maps app though, and it looks like they don't restart the activity that displays a map at all. Do we need to use configurationChanged="orientation" on activities with maps? WIll it help maintain the state?

    点赞 评论 复制链接分享
  • weixin_39519619 weixin_39519619 2021-01-08 11:57

    Update - my fix didn't really work, crash is still there on some of devices

    点赞 评论 复制链接分享
  • weixin_39519619 weixin_39519619 2021-01-08 11:57

    https://code.google.com/p/gmaps-api-issues/issues/detail?id=9871

    点赞 评论 复制链接分享
  • weixin_39519619 weixin_39519619 2021-01-08 11:57

    Looks like I have found another workaround for the issue. Before doing anything asynchronous with a marker, check clusterManager.markerCollection.markers.contains(marker) and proceed only if it's true - when clustermanager is removing markers for whatever reason, it first removes the marker from this markers array, but it can still fail somehow later removing actual marker from the map.

    Additionally, wrap your calls to marker.setIcon() with try/catch of IllegalArgumentException, and also place this repo as a source library and change this method in MarkerManager.java:

    
    public boolean remove(Marker marker) {
                if (mMarkers.remove(marker)) {
                    mAllMarkers.remove(marker);
                    try {
                        marker.remove();
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
    
                    return true;
                }
                return false;
            }
    
    点赞 评论 复制链接分享
  • weixin_39947306 weixin_39947306 2021-01-08 11:57

    For anyone else wondering why this may be occurring, here are the exact steps to reproduce the issue

    1. Place few markers to form a cluster.
    2. Zoom in to the map so all markers appears individually on map.
    3. Run an long duration animation on the marker like simple animation changing marker icon
    4. Zoom out so that marker goes back to cluster, invalidating this marker's reference.
    5. Crash occurs with "java.lang.IllegalArgumentException: Released unknown imageData reference". due to animation attempt to update marker.

    As per the steps, this seems like a incorrect maps api usage issue.

    点赞 评论 复制链接分享
  • weixin_39875842 weixin_39875842 2021-01-08 11:57

    This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

    点赞 评论 复制链接分享
  • weixin_39875842 weixin_39875842 2021-01-08 11:57

    Closing this. Please reopen if you believe it should be addressed. Thank you for your contribution.

    点赞 评论 复制链接分享

相关推荐