1

I found open source blur background image code and using my project, but some times get this error. not all some times.

java.lang.ArrayIndexOutOfBoundsException: length=1290496; index=1297040
        at com.cleanwiz.applock.utils.FastBlur.doBlur(FastBlur.java:130)
        at com.cleanwiz.applock.ui.activity.GestureUnlockActivity.blur(GestureUnlockActivity.java:524)
        at com.cleanwiz.applock.ui.activity.GestureUnlockActivity.access$200(GestureUnlockActivity.java:76)
        at com.cleanwiz.applock.ui.activity.GestureUnlockActivity$1.onPreDraw(GestureUnlockActivity.java:159)
        at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:833)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1860)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
        at android.view.Choreographer.doCallbacks(Choreographer.java:562)
        at android.view.Choreographer.doFrame(Choreographer.java:532)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
        at android.os.Handler.handleCallback(Handler.java:730)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5103)
        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:737)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

Here My FastBlur.doBlur(FastBlur.java:130)

 for (x = 0; x < w; x++) {

            r[yi] = dv[rsum];
            g[yi] = dv[gsum];
            b[yi] = dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

Here My GestureUnlockActivity.blur(GestureUnlockActivity.java:524)

private void blur(Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 70;
    float scaleFactor = 8;

    Bitmap overlay = Bitmap.createBitmap(
            (int) (view.getMeasuredWidth() / scaleFactor),
            (int) (view.getMeasuredHeight() / scaleFactor),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop()
            / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(getResources(), overlay));
}

Here My GestureUnlockActivity$1.onPreDraw(GestureUnlockActivity.java:159)

blur(big(bmp), backLinearLayout);

And Here My Array

int[] pixex = new int[w * h];
    List<Integer> trIndexs = new ArrayList<Integer>();
    for (int i = 0; i < bitmap.getHeight(); i++) {
        for (int j = 0; j < bitmap.getWidth(); j++) {
            int color = bitmap.getPixel(j, i);
            int alpha = Color.alpha(color);
            if (alpha < 200) {
                trIndexs.add(i * h + j);
            } else if (trIndexs.size() > 0) {
                for (Integer tr : trIndexs) {
                    pixex[tr] = color;
                }
                trIndexs.clear();
                pixex[i * h + j] = color;
            } else {
                pixex[i * h + j] = color;
            }
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    How about the debug mode? Set a breakpoint at your `for-iteration` at `FastBlur` an outofbounds should be easy to locate. Dont expect us to understand your bucket of code instantly(its not even documented!) – Tom Wellbrock Sep 28 '15 at 17:43

1 Answers1

0

I am seeing a similar crash using the fastBlur algorithm. I am getting crashes primarily on Android 4.0 devices.

Judging from the comments here and here, it looks like it could potentially be a memory related issue. Only suggestion I saw was to break large images into tiles and blur those smaller tiles.

Community
  • 1
  • 1
benjamin davis
  • 680
  • 6
  • 12