diff --git a/FlipView/FlipLibrary/src/com/aphidmobile/flip/ViewDualCards.java b/FlipView/FlipLibrary/src/com/aphidmobile/flip/ViewDualCards.java index 35e1c20..94e4d24 100644 --- a/FlipView/FlipLibrary/src/com/aphidmobile/flip/ViewDualCards.java +++ b/FlipView/FlipLibrary/src/com/aphidmobile/flip/ViewDualCards.java @@ -54,7 +54,7 @@ public View getView() { return viewRef != null ? viewRef.get() : null; } - public boolean setView(int index, View view) { + public synchronized boolean setView(int index, View view) { UI.assertInMainThread(); if (this.index == index @@ -71,21 +71,19 @@ && getView() == view } if (view != null) { viewRef = new WeakReference(view); - UI.recycleBitmap(screenshot); + recycleScreenshot(); screenshot = GrabIt.takeScreenshot(view); } else { - UI.recycleBitmap(screenshot); - screenshot = null; + recycleScreenshot(); } return true; } - void markForceReload() { + synchronized void markForceReload() { UI.assertInMainThread(); - UI.recycleBitmap(screenshot); - screenshot = null; + recycleScreenshot(); if (texture != null) { texture.postDestroy(); texture = null; @@ -108,13 +106,12 @@ public Card getBottomCard() { return bottomCard; } - public void buildTexture(FlipRenderer renderer, GL10 gl) { + public synchronized void buildTexture(FlipRenderer renderer, GL10 gl) { if (screenshot != null) { if (texture != null) texture.destroy(gl); texture = Texture.createTexture(screenshot, renderer, gl); - UI.recycleBitmap(screenshot); - screenshot = null; + recycleScreenshot(); topCard.setTexture(texture); bottomCard.setTexture(texture); @@ -181,7 +178,7 @@ public void buildTexture(FlipRenderer renderer, GL10 gl) { } } - public void abandonTexture() { + public synchronized void abandonTexture() { texture = null; } @@ -189,4 +186,9 @@ public void abandonTexture() { public String toString() { return "ViewDualCards: (" + index + ", view: " + getView() + ")"; } + + private void recycleScreenshot() { + UI.recycleBitmap(screenshot); + screenshot = null; + } } diff --git a/FlipView/FlipLibrary/src/com/aphidmobile/utils/UI.java b/FlipView/FlipLibrary/src/com/aphidmobile/utils/UI.java index b01cdae..ba62112 100644 --- a/FlipView/FlipLibrary/src/com/aphidmobile/utils/UI.java +++ b/FlipView/FlipLibrary/src/com/aphidmobile/utils/UI.java @@ -40,8 +40,12 @@ public static void assertInMainThread() { } public static void recycleBitmap(Bitmap bm) { - if (bm != null) - bm.recycle(); + if (bm != null) { + if (bm.isRecycled()) + AphidLog.w("Bitmap is recycled already?"); + else + bm.recycle(); + } } public static T callInMainThread(Callable call) throws Exception {