Skip to content

Commit

Permalink
CacheManagingDrawTask: try-catch/retry subnew to avoid the Concurrent…
Browse files Browse the repository at this point in the history
…ModificationException
  • Loading branch information
ctiao committed Sep 21, 2015
1 parent 76bb26b commit 57fbaa5
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package master.flame.danmaku.controller;

import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;

import master.flame.danmaku.danmaku.model.AbsDisplayer;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
Expand Down Expand Up @@ -559,15 +559,22 @@ private void releaseDanmakuCache(BaseDanmaku item, DrawingCache cache) {

private long prepareCaches(boolean repositioned) {
long curr = mCacheTimer.currMillisecond;
long end = curr + DanmakuFactory.MAX_DANMAKU_DURATION * mScreenSize * 3;
long end = curr + DanmakuFactory.MAX_DANMAKU_DURATION * mScreenSize;
if (end < mTimer.currMillisecond) {
return 0;
}
long startTime = System.currentTimeMillis();
long startTime = System.currentTimeMillis();
IDanmakus danmakus = null;
synchronized (danmakuList) {
danmakus = danmakuList.subnew(curr, end);
}
int tryCount = 0;
boolean hasException = false;
do {
try {
danmakus = danmakuList.subnew(curr, end);
} catch (Exception e) {
hasException = true;
SystemClock.sleep(10);
}
} while (++tryCount < 3 && danmakus == null && hasException);
if (danmakus == null) {
mCacheTimer.update(end);
return 0;
Expand Down

0 comments on commit 57fbaa5

Please sign in to comment.