From 3eb2e643a40d1be77998373343cdf8b14764f58c Mon Sep 17 00:00:00 2001 From: Bobby Georgescu Date: Mon, 24 Sep 2012 11:26:10 -0700 Subject: [PATCH] Fix occasional crash when restoring photo page state Bug: 7216012 If the saved state being used to restore the photo page includes an out-of-bounds index, ignore it and reset the index to 0. Change-Id: I1b8aa82cbc553297189abb57bd274d7eb53f61e0 --- src/com/android/gallery3d/app/PhotoPage.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index c5c77e11b..b1736203c 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -353,10 +353,13 @@ public class PhotoPage extends ActivityState implements Log.w(TAG, "failed to restore " + mSetPathString); } if (itemPath == null) { - if (mMediaSet.getMediaItemCount() > 0) { + int mediaItemCount = mMediaSet.getMediaItemCount(); + if (mediaItemCount > 0) { + if (mCurrentIndex >= mediaItemCount) mCurrentIndex = 0; itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1) .get(0).getPath(); } else { + // Bail out, PhotoPage can't load on an empty album return; } } -- 2.11.0