From 269a1016de3994b2a4db0e1a74b32352fd21e9f5 Mon Sep 17 00:00:00 2001 From: Alan Sheridan Date: Tue, 8 Dec 2015 16:27:02 -0800 Subject: [PATCH] Prevent crash on null Map Projection There are race conditions that seem to be able to result in multiple map initializations causing a null projection for a tiny amount of time, this will cause several crashes if we don't properly protect ourselves from them. --- .../android/clustering/view/DefaultClusterRenderer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java b/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java index 6b9e0df41..8d1e8ec6b 100644 --- a/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java +++ b/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java @@ -264,6 +264,11 @@ public void handleMessage(Message msg) { // Nothing to do. return; } + Projection projection = mMap.getProjection(); + if (projection == null) { + // Without a map projection we can't render clusters. + return; + } RenderTask renderTask; synchronized (this) { @@ -278,7 +283,7 @@ public void run() { sendEmptyMessage(TASK_FINISHED); } }); - renderTask.setProjection(mMap.getProjection()); + renderTask.setProjection(projection); renderTask.setMapZoom(mMap.getCameraPosition().zoom); new Thread(renderTask).start(); }