aelmahalawey / androidsvg

Automatically exported from code.google.com/p/androidsvg
0 stars 0 forks source link

SVGImageView crashes on Android 5.0 and higher #60

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Using the following code will crash 5.0 and above with a segfault from the OS:

private FrameLayout mIdCardContainer;
private SVGImageView mIdCardBackImage;
private SVGImageView mIdCardFrontImage;

mIdCardFrontImage = new SVGImageView(getActivity());
mIdCardFrontImage.setId(R.id.img_id_card_front);
mIdCardFrontImage.setLayoutParams(new 
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
ViewGroup.LayoutParams.MATCH_PARENT));
mIdCardFrontImage.setContentDescription(getString(R.string.front_of_id_card));
mIdCardFrontImage.setRotation(ROTATION_ANGLE);

// Setup special SVGImageViews for back of card
mIdCardBackImage = new SVGImageView(getActivity());
mIdCardBackImage.setId(R.id.img_id_card_back);
mIdCardBackImage.setLayoutParams(new 
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
ViewGroup.LayoutParams.MATCH_PARENT));
mIdCardBackImage.setContentDescription(getString(R.string.back_of_id_card));
mIdCardBackImage.setRotation(ROTATION_ANGLE);
mIdCardBackImage.setVisibility(View.GONE);

SVG frontSvg = SVG.getFromString( idCard.getCardFrontData() );
SVG backSvg = SVG.getFromString( idCard.getCardBackData() );

mIdCardFrontImage.setSVG(frontSvg);
mIdCardBackImage.setSVG(backSvg);

What is the expected output? What do you see instead?
Some devices crash immediately on setting the images others fail miserably when 
the two images are flipped with an animation front -> tap -> back -> tap -> 
crash

What version of the product are you using? On what operating system?
1.2.2-beta-1

Please provide any additional information below.
This works fine on 4.1-4.4.2
This does not work at all on Genymotion, or on certain devices.
The crash after flipping back to the front image crashes on the Samsung S6 
running 5.0.2, but works on a nexus 5 running 5.0.

Original issue reported on code.google.com by troo...@itriagehealth.com on 7 May 2015 at 6:47

GoogleCodeExporter commented 9 years ago
Thanks for the report.  Can you provide a copy of the segfault message?

Original comment by paul.leb...@gmail.com on 8 May 2015 at 1:34

GoogleCodeExporter commented 9 years ago
12951-12951/com.mycompany.appname A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, 
fault addr 0xdf51f00c in tid 12951 (a.appname)
05-06 14:03:18.137    2975-2975/? I/DEBUG﹕ *** *** *** *** *** *** *** *** 
*** *** *** *** *** *** *** ***
05-06 14:03:18.137    2975-2975/? I/DEBUG﹕ Build fingerprint: 
'Verizon/zerofltevzw/zerofltevzw:5.0.2/LRX22G/G920VVRU1AOC3:user/release-keys'
05-06 14:03:18.137    2975-2975/? I/DEBUG﹕ Revision: '10'
05-06 14:03:18.137    2975-2975/? I/DEBUG﹕ ABI: 'arm'
05-06 14:03:18.137    2975-2975/? I/DEBUG﹕ pid: 12951, tid: 12951, name: 
a.appname  >>> com.mycompany.appname <<<
05-06 14:03:18.137    2975-2975/? I/DEBUG﹕ signal 11 (SIGSEGV), code 1 
(SEGV_MAPERR), fault addr 0xdf51f00c
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ r0 0000003e  r1 ffcf3004  r2 
00000000  r3 d9094ff0
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ r4 d9094ff0  r5 df51f00c  r6 
ffcf300c  r7 000000fe
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ r8 00000000  r9 ffcf3000  sl 
00000000  fp 0000003f
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ ip 00020001  sp ffcf2fcc  lr 
f5fdc783  pc f60c662a  cpsr 400f0030
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ backtrace:
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #00 pc 001ba62a  
/system/lib/libskia.so (S32_opaque_D32_nofilter_DX_neon(SkBitmapProcState 
const&, unsigned int const*, int, unsigned int*)+73)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #01 pc 000d0781  
/system/lib/libskia.so 
(SkBitmapProcShader::BitmapProcShaderContext::shadeSpan(int, int, unsigned 
int*, int)+86)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #02 pc 000d926d  
/system/lib/libskia.so (SkARGB32_Shader_Blitter::blitRect(int, int, int, 
int)+242)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #03 pc 0010b0cb  
/system/lib/libskia.so
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #04 pc 0010b197  
/system/lib/libskia.so (SkScan::FillIRect(SkIRect const&, SkRegion const*, 
SkBlitter*)+198)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #05 pc 0010b267  
/system/lib/libskia.so (SkScan::FillRect(SkRect const&, SkRegion const*, 
SkBlitter*)+136)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #06 pc 0010b357  
/system/lib/libskia.so (SkScan::FillRect(SkRect const&, SkRasterClip const&, 
SkBlitter*)+56)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #07 pc 000e599b  
/system/lib/libskia.so (SkDraw::drawRect(SkRect const&, SkPaint const&) 
const+366)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #08 pc 000e6787  
/system/lib/libskia.so (SkDraw::drawBitmap(SkBitmap const&, SkMatrix const&, 
SkPaint const&) const+326)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #09 pc 000dea79  
/system/lib/libskia.so
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #10 pc 000deb61  
/system/lib/libskia.so (SkCanvas::drawBitmap(SkBitmap const&, float, float, 
SkPaint const*)+116)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #11 pc 000fe70f  
/system/lib/libskia.so (SkPicturePlayback::draw(SkCanvas&, 
SkDrawPictureCallback*)+1186)
05-06 14:03:18.177    2975-2975/? I/DEBUG﹕ #12 pc 000b3c5f  
/system/framework/arm/boot.oat
05-06 14:03:18.557    2975-2975/? I/DEBUG﹕ Tombstone written to: 
/data/tombstones/tombstone_02
05-06 14:03:18.557    2975-2975/? E/﹕ !@dumpstate -k -t -z -d -o 
/data/log/dumpstate_app_native -m 12951
05-06 14:03:18.557    3508-3601/? I/BootReceiver﹕ Copying 
/data/tombstones/tombstone_02 to DropBox (SYSTEM_TOMBSTONE)
05-06 14:03:18.557    3508-7261/? W/System.err﹕ mkdir failed: EROFS 
(Read-only file system) : shared_prefs
05-06 14:03:18.557    3508-7261/? E/SharedPreferencesImpl﹕ Couldn't create 
directory for SharedPreferences file shared_prefs/log_files.xml
05-06 14:03:18.567  13109-13109/? I/dumpstate﹕ begin
05-06 14:03:18.587   3508-13108/? W/ActivityManager﹕ Force finishing activity 
com.mycompany.appname/.activities.IDCardActivity
05-06 14:03:18.607    3508-3552/? D/PhoneWindow﹕ *FMB* installDecor 
mIsFloating : true
05-06 14:03:18.607    3508-3552/? D/PhoneWindow﹕ *FMB* installDecor flags : 
8519682
05-06 14:03:18.617  13114-13114/? I/dumpstate﹕ begin
05-06 14:03:18.617  13114-13114/? I/dumpstate﹕ dumpstate is still running
05-06 14:03:18.637    3508-3623/? D/StatusBarManagerService﹕ 
manageDisableList userId=0 what=0x0 pkg=WindowManager.LayoutParams
05-06 14:03:18.637    3508-3629/? D/PointerIcon﹕ setMouseIconStyle1 
pointerType: 1001iconType:101 flag:0
05-06 14:03:18.637    3508-3629/? D/PointerIcon﹕ setMouseCustomIcon IconType 
is same.101
05-06 14:03:18.647  11179-11179/? I/LoadedApk﹕ getClassLoader 
:dalvik.system.PathClassLoader[DexPathList[[zip file 
"/system/priv-app/Amazon_Appstore/Amazon_Appstore.apk"],nativeLibraryDirectories
=[/system/priv-app/Amazon_Appstore/lib/arm, /vendor/lib, /system/lib]]]
05-06 14:03:18.647  11179-11179/? 
I/AmazonAppstore.AbstractReportBroadcastReceiver﹕ Ignoring entry for 
data_app_native_crash, not a supported report type
05-06 14:03:18.647    3508-3552/? D/PhoneWindow﹕ *FMB* isFloatingMenuEnabled 
mFloatingMenuBtn : null
05-06 14:03:18.647    3508-3552/? D/PhoneWindow﹕ *FMB* isFloatingMenuEnabled 
return false
05-06 14:03:18.647    3508-3508/? D/CrashAnrDetector﹕ Build: 
Verizon/zerofltevzw/zerofltevzw:5.0.2/LRX22G/G920VVRU1AOC3:user/release-keys
    Hardware: universal7420
    Revision: 10
    Bootloader: G920VVRU1AOC3
    Radio: unknown
    Kernel: Linux version 3.10.61-4318389 (dpi@SWDD5701) (gcc version 4.9 20140514 (prerelease) (GCC) ) #1 SMP PREEMPT Fri Mar 20 19:48:32 KST 2015
    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    Build fingerprint: 'Verizon/zerofltevzw/zerofltevzw:5.0.2/LRX22G/G920VVRU1AOC3:user/release-keys'
    Revision: '10'
    ABI: 'arm'
    pid: 12951, tid: 12951, name: a.appname  >>> com.mycompany.appname <<<
    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xdf51f00c
    r0 0000003e  r1 ffcf3004  r2 00000000  r3 d9094ff0
    r4 d9094ff0  r5 df51f00c  r6 ffcf300c  r7 000000fe
    r8 00000000  r9 ffcf3000  sl 00000000  fp 0000003f
    ip 00020001  sp ffcf2fcc  lr f5fdc783  pc f60c662a  cpsr 400f0030
    d0  3e4b50003f45a5a5  d1  3e4b50004434a000
    d2  3dcb4c00564b5000  d3  0000005955cb4c00
    d4  00c36d7a00c2a7d5  d5  00c4f8c400c4331f
    d6  42b3000000000059  d7  3dcb4c003f45a5a6
    d8  43ef00003f000000  d9  42b2000044348000
    d10 3f80000000000000  d11 0000000000000000
    d12 0000000000000000  d13 0000000000000000
    d14 0000000000000000  d15 0000000000000000
    d16 00c056e600bf9141  d17 00c1e23000c11c8b
    d18 0003169400031694  d19 0003169400031694
    d20 00062d2800062d28  d21 00062d2800062d28
    d22 00bb00ba00ba00b9  d23 00be00be00bd00bc
    d24 b508ef6329be6419  d25 cb9c05f740527aad
    d26 405994b940000000  d27 0000000000000000
    d28 3ff4b94b9415aa40  d29 0000000000000000
    d30 3fbb1909b1a5a8f6  d31 bfc4c5952d8218c7
    scr 20000013
    backtrace:
    #00 pc 001ba62a  /system/lib/libskia.so (S32_opaque_D32_nofilter_DX_neon(SkBitmapProcState const&, unsigned int const*, int, unsigned int*)+73)
    #01 pc 000d0781  /system/lib/libskia.so (SkBitmapProcShader::BitmapProcShaderContext::shadeSpan(int, int, unsigned int*, int)+86)
    #02 pc 000d926d  /system/lib/libskia.so (SkARGB32_Shader_Blitter::blitRect(int, int, int, int)+242)
    #03 pc 0010b0cb  /system/lib/libskia.so
    #04 pc 0010b197  /system/lib/libskia.so (SkScan::FillIRect(SkIRect const&, SkRegion const*, SkBlitter*)+198)
    #05 pc 0010b267  /system/lib/libskia.so (SkScan::FillRect(SkRect const&, SkRegion const*, SkBlitter*)+136)
    #06 pc 0010b357  /system/lib/libskia.so (SkScan::FillRect(SkRect const&, SkRasterClip const&, SkBlitter*)+56)
    #07 pc 000e599b  /system/lib/libskia.so (SkDraw::drawRect(SkRect const&, SkPaint const&) const+366)
    #08 pc 000e6787  /system/lib/libskia.so (SkDraw::drawBitmap(SkBitmap const&, SkMatrix const&, SkPaint const&) const+326)
    #09 pc 000dea79  /system/lib/libskia.so
    #10 pc 000deb61  /system/lib/libskia.so (SkCanvas::drawBitmap(SkBitmap const&, float, float, SkPaint const*)+116)
    #11 pc 000fe70f  /system/lib/libskia.so (SkPicturePlayback::draw(SkCanvas&, SkDrawPictureCallback*)+1186)
    #12 pc 000b3c5f  /system/framework/arm/boot.oat
    stack:
    ffcf2f4c  00000051
    ffcf2f50  0000006f
    ffcf2f54  f601665d  /system/lib/libskia.so (SkScalerContext::getMetrics(SkGlyph*)+22)
    ffcf2f58  00000000
    ffcf2f5c  00000000
    ffcf2f60  ffcf30f0  [stack]
    ffcf2f64  000003d5
    ffcf2f68  ffcf3004  [stack]
    ffcf2f6c  f5fe19f5  /system/lib/libskia.so
    ffcf2f70  d9c82648  /dev/ashmem/dalvik-large object space allocation (deleted)
    ffcf2f74  ff000000
    ffcf2f78  00001540
    ffcf2f7c  03daf8b0
    ffcf2f80  00000001
    ffcf2f84  55cb4c00
    ffcf2f88  00000000
    ffcf2f8c  00000000
    ffcf2f90  42b96980  /dev/ashmem/dalvik-main space (deleted)
    ffcf2f94  f758510c  /system/lib/libm.so (__aeabi_f2ulz+72)
    ffcf2f98  ffcf3a08  [stack]
    ffcf2f9c  f5ffcbd5  /system/lib/libskia.so (SkMatrix::ScaleTrans_xy(SkMatrix const&, float, float, SkPoint*))
    ffcf2fa0  ffcf3000  [stack]
    ffcf2fa4  f60c9ca5  /system/lib/libskia.so
    ffcf2fa8  ffc
05-06 14:03:18.647    3508-3508/? D/CrashAnrDetector﹕ 
processName:com.mycompany.appname
05-06 14:03:18.647    3508-3508/? D/CrashAnrDetector﹕ broadcastEvent : 
com.mycompany.appname SYSTEM_TOMBSTONE
05-06 14:03:18.647    3508-3508/? W/ContextImpl﹕ Calling a method in the 
system process without a qualified user: 
android.app.ContextImpl.sendBroadcast:1714 
com.android.server.analytics.data.collection.application.CrashAnrDetector.broadc
astEvent:296 
com.android.server.analytics.data.collection.application.CrashAnrDetector.proces
sDropBoxEntry:254 
com.android.server.analytics.data.collection.application.CrashAnrDetector.access
$100:60 
com.android.server.analytics.data.collection.application.CrashAnrDetector$1.onRe
ceive:102

Original comment by troo...@itriagehealth.com on 8 May 2015 at 2:06

GoogleCodeExporter commented 9 years ago
Thanks for that.

The good news for me is that this doesn't look like an AndroidSVG fault :)

It looks like the problem is in Skia, which is the 2D rendering library in 
Android.

I've passed this on to the Android bugtracker.  
https://code.google.com/p/android/issues/detail?id=172402

I will probably end up marking this as Won't Fix, but if you have any more 
detail on the cause, please send it through.  For example:

* Does it happen for some SVGs and not others?  If so, are you able to attach 
one of the failing SVGs?
* If you simplify the code - for example, removing the rotations - can you get 
it to stop faulting?  It would be good to find a work-around in case other 
people strike this also.

Original comment by paul.leb...@gmail.com on 8 May 2015 at 3:18

GoogleCodeExporter commented 9 years ago
Sadly I can not attach the svg, its an internal testing one and I dont think 
it'd be the best thing if I sent it out.  NDAs and the like.

I got around it by instead of using the SVGImageView, I had it render to a 
bitmap and used an ImageView to show that.  It worked quite happily there.  
I'll have to try other SVGs and remove the animation to flip between the two 
views and see what happens.

My work around was something like this:
mIdCardFrontImage = (ImageView)rootView.findViewById(R.id.img_id_card_front);
mIdCardFrontImage.setContentDescription(getString(R.string.front_of_id_card));
mIdCardFrontImage.setRotation(ROTATION_ANGLE);

mIdCardBackImage = (ImageView)rootView.findViewById(R.id.img_id_card_back);
mIdCardBackImage.setContentDescription(getString(R.string.back_of_id_card));
mIdCardBackImage.setRotation(ROTATION_ANGLE);
mIdCardBackImage.setVisibility(View.GONE);

The image is pulled dynamically from a server, so this happens asynchronously 
after the image views and its parent is already laid out and sized correctly 
for this to work.

// Changes to how this works to fix the lollipop crash
            // Make the SVG from the data returned from the server
            mFrontSVG = SVG.getFromString( idCard.getCardFrontData() );
            mBackSVG = SVG.getFromString( idCard.getCardBackData() );

            //Scale the image up so it fits on the screen better and isn't tiny or fuzzy
            //Sharpness is preserved because its a vector image. Yay!
            mFrontSVG.setDocumentPreserveAspectRatio(PreserveAspectRatio.LETTERBOX);
            mFrontSVG.setDocumentHeight(mIdCardFrontImage.getWidth());
            mFrontSVG.setDocumentWidth(mIdCardFrontImage.getHeight());

            //Scale here as well, but because mIdCardBackImage is gone, it doesn't have a
            //height or width.  So use the front image height and width.
            mBackSVG.setDocumentPreserveAspectRatio(PreserveAspectRatio.LETTERBOX);
            mBackSVG.setDocumentHeight(mIdCardFrontImage.getWidth());
            mBackSVG.setDocumentWidth(mIdCardFrontImage.getHeight());

            //Render these two images to bitmaps set to a background color of transparent.
            //I did not want to use a function with these since we are using bitmaps and
            //passing them around could quickly lead to memory problems.
            if (mFrontSVG.getDocumentWidth() != -1) {
                //Create the bitmap the same size as the scaled SVG
                Bitmap  newBM = Bitmap.createBitmap((int)Math.ceil(mFrontSVG.getDocumentWidth()),
                        (int)Math.ceil(mFrontSVG.getDocumentHeight()),
                        Bitmap.Config.ARGB_8888);
                //Create a canvas to sit atop the bitmap to allow drawing
                Canvas bmcanvas = new Canvas(newBM);
                // Clear background to transparent
                bmcanvas.drawARGB(0, 0, 0, 0);
                // Render our document onto our canvas
                mFrontSVG.renderToCanvas(bmcanvas);
                //set the imageview to the new bitmap
                mIdCardFrontImage.setImageBitmap(newBM);

                //clean up and call the garbage collection to avoid any potential memory issues
                newBM = null;
                System.gc();
            }

Pretty much using the code sample from the project webpage.  The flip is still 
there, and doesn't crash.  Granted the above somewhat defeats the purpose of 
the svg, but it worked in this case.  

Thank you for making a library that handles SVG. 

Original comment by troo...@itriagehealth.com on 8 May 2015 at 3:26

GoogleCodeExporter commented 9 years ago
The Skia folks have asked for more information.  Can you try their suggestions 
and follow up there?

https://code.google.com/p/skia/issues/detail?id=3820

Thanks

Original comment by paul.leb...@gmail.com on 11 May 2015 at 7:30