0

I'd like to animate a sprite. I select the current frame by BitmapRegionDecoder, but it causes native crash on some Anroid 6.0 devices (mainly on Samsung). I get this stack trace:


Build fingerprint: 'samsung/zeroltexx/zerolte:6.0.1/MMB29K/G925FXXU4DPGW:user/release-keys' Revision: '10' ABI: 'arm64' pid: 10872, tid: 10872, name: .aff.index.main >>> com.aff.index.main <<< signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x30 x0 0000000000000000 x1 0000000000000000 x2 0000000000000002 x3 0000000000000000 x4 0000000000000000 x5 00000000ffffffff x6 0000000000000000 x7 0000000000000000 x8 0000000000000000 x9 0000000000000000 x10 0000000000000000 x11 0000000000000000 x12 0000007f1d0fd5c8 x13 0000000000000002 x14 0000000000000000 x15 000000c8000000c5 x16 0000007f7931c5f8 x17 0000007f7925e3dc x18 0000000000000000 x19 0000000000000000 x20 0000007f7563d180 x21 0000000000000001 x22 0000000000000000 x23 0000000000000000 x24 0000000000000000 x25 0000000000000000 x26 00000000ffffffff x27 0000000000000000 x28 0000000000000000 x29 0000007fead6d070 x30 0000007f79264348 sp 0000007fead6d050 pc 0000007f7925e3dc pstate backtrace: #00 pc 00000000000f23dc /system/lib64/libandroid_runtime.so (_ZNK7android6Bitmap4infoEv) #01 pc 00000000000f8344 /system/lib64/libandroid_runtime.so (_ZN11GraphicsJNI12createBitmapEP7_JNIEnvPN7android6BitmapEiP11_jbyteArrayP8_jobjecti+60) #02 pc 0000000000104224 /system/lib64/libandroid_runtime.so #03 pc 0000000003f6b77c /system/framework/arm64/boot.oat (offset 0x2f37000)

I call this runnable inside a View

   @Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    try {
        if (isInited && region != null) canvas.drawBitmap(region, 0, 0, paint);
    } catch (Throwable t) {
        Timber.w(t, null);
    }
}

class AnimatePlaceholderRunnable implements Runnable {
    @Override
    public void run() {
        try {
            if (Build.VERSION.SDK_INT < 10) return;
            if (!isAnimating) return;
            if ((top + height + empty) <= maxTop) top = top + height + empty;
            else
                top = 0;
            bottom = top + height;
            src = new Rect(left, top, right, bottom);
            region = decoder.decodeRegion(src, null);
            invalidate();
            postDelayed(placeholderRunnable, 41);
        } catch (Throwable t) {
            Timber.w(t, null);
        }
    }
}

On many devices it runs well, e.g. on Nexus 6.0 with Android 7.0 or on a Sony XPeria Z1 with Android 5.x, but on my Samsung Galaxy S6 with Android 6.x my app crashes.

1 Answer 1

1

I had a similar problem once. The issue was that I was using a library that didn't bundle 64-bit arm code. Android has a bug where it assumes that if one library bundles 64-bit native code, that it assumes all libraries that use native code has 64-bit code in there. I believe Galaxy S7 is a 64bit phone. Check your exploded apk to see if this is the case.

You can load the entire sprint and crop regions from it using Java code. You can find the answer on how to do that in this article. Android Devs, make your Toolbar and View backgrounds frosty

In short:

Matrix matrix = new Matrix();
//half the size of the cropped bitmap
//to increase performance, it will also
//increase the blur effect.
matrix.setScale(0.5f, 0.5f);
Bitmap bitmap = Bitmap.createBitmap(spriteBitmap,
    (int) targetView.getX(), //start x
    (int) targetView.getY(), //start y
    targetView.getMeasuredWidth(), //end x
    targetView.getMeasureHeight(), //end y
    matrix,
    true);

My recommendation is to fall back on this if the first method didn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.