Occasional Crash in libskia.so

Hi All,

Is anybody experiencing crashes in libskia.so ~ triggered by BitmapDC::getBitmapFromJavaShadowStroke

 ********** Crash dump: **********
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000003
Stack frame #00  pc 0000f9f6  /system/lib/libc.so (dlmalloc+1209)
Stack frame #01  pc 0000d9ab  /system/lib/libc.so (malloc+10)
Stack frame #02  pc 00124010  /system/lib/libskia.so (sk_malloc_flags(unsigned int, unsigned int)+8)
Stack frame #03  pc 00090158  /system/lib/libskia.so (SkChunkAlloc::newBlock(unsigned int, SkChunkAlloc::AllocFailType)+36)
Stack frame #04  pc 000901c8  /system/lib/libskia.so (SkChunkAlloc::alloc(unsigned int, SkChunkAlloc::AllocFailType)+48)
Stack frame #05  pc 000a2374  /system/lib/libskia.so (SkGlyphCache::lookupMetrics(unsigned int, SkGlyphCache::MetricsType)+216)
Stack frame #06  pc 000a2534  /system/lib/libskia.so (SkGlyphCache::getGlyphIDMetrics(unsigned short)+56)
Stack frame #07  pc 000ae52c  /system/lib/libskia.so (SkPaint::getTextWidths(void const*, unsigned int, float*, SkRect*) const+272)
Stack frame #08  pc 00075e4f  /system/lib/libandroid_runtime.so
Stack frame #09  pc 00026d04  /system/lib/libharfbuzz_ng.so
Stack frame #10  pc 0000cd60  /system/lib/libharfbuzz_ng.so (hb_shape_plan_execute+208)
Stack frame #11  pc 0000c728  /system/lib/libharfbuzz_ng.so (hb_shape_full+80)
Stack frame #12  pc 0000c760  /system/lib/libharfbuzz_ng.so (hb_shape+16)
Stack frame #13  pc 0007b6ef  /system/lib/libandroid_runtime.so (android::TextLayoutShaper::shapeFontRun(SkPaint const*)+202)
Stack frame #14  pc 0007b7d1  /system/lib/libandroid_runtime.so (android::TextLayoutShaper::computeRunValues(SkPaint const*, unsigned short const*, unsigned int, unsigned int, unsigned int, bool, android::Vector<float>*, float*, android::Vector<unsigned short>*, android::Vector<float>*)+210)
Stack frame #15  pc 0007ba8b  /system/lib/libandroid_runtime.so (android::TextLayoutShaper::computeValues(SkPaint const*, unsigned short const*, unsigned int, unsigned int, unsigned int, int, android::Vector<float>*, float*, android::Vector<unsigned short>*, android::Vector<float>*)+422)
Stack frame #16  pc 0007bb31  /system/lib/libandroid_runtime.so (android::TextLayoutShaper::computeValues(android::TextLayoutValue*, SkPaint const*, unsigned short const*, unsigned int, unsigned int, unsigned int, int)+44)
Stack frame #17  pc 0007bfef  /system/lib/libandroid_runtime.so (android::TextLayoutCache::getValue(SkPaint const*, unsigned short const*, int, int, int, int)+274)
Stack frame #18  pc 0007c313  /system/lib/libandroid_runtime.so (android::TextLayoutEngine::getValue(SkPaint const*, unsigned short const*, int, int, int, int)+34)
Stack frame #19  pc 0007ac27  /system/lib/libandroid_runtime.so (android::TextLayout::getTextRunAdvances(SkPaint*, unsigned short const*, int, int, int, int, float*, float*)+42)
Stack frame #20  pc 000779bb  /system/lib/libandroid_runtime.so
Stack frame #21  pc 0001dc4c  /system/lib/libdvm.so (dvmPlatformInvoke+112)
Stack frame #22  pc 0004dcab  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+394)
Stack frame #23  pc 000385e1  /system/lib/libdvm.so (dvmCheckCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+8)
Stack frame #24  pc 00027060  /system/lib/libdvm.so
Stack frame #25  pc 0002b580  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
Stack frame #26  pc 0005fcbd  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+292)
Stack frame #27  pc 000499ab  /system/lib/libdvm.so
Stack frame #28  pc 0003cb3d  /system/lib/libdvm.so
Stack frame #29  pc 001ae690  /data/app-lib/…../libgame.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+60): Routine _JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...) at /…./android/android-ndk-r9c/platforms/android-13/arch-arm/usr/include/jni.h:807
Stack frame #30  pc 0028b2b8  /data/app-lib/.../libgame.so (cocos2d::BitmapDC::getBitmapFromJavaShadowStroke(char const*, int, int, cocos2d::CCImage::ETextAlign, char const*, float, float, float, float, bool, float, float, float, float, bool, float, float, float, float)+648): Routine cocos2d::BitmapDC::getBitmapFromJavaShadowStroke(char const*, int, int, cocos2d::CCImage::ETextAlign, char const*, float, float, float, float, bool, float, float, float, float, bool, float, float, float, float) at 

I’m using NDK r9c. Bug occasionally happens on any Android version, and does not always have the same stack trace - but is always crashing in libskia.so

Thanks

Stacks in here look familiar?

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

https://code.google.com/p/android/issues/detail?id=58515

Thanks for those links Cory,
I starred the bugs in hopes they’ll fix the issue. But now I’m wondering if there’s something I can do to prevent this.

In testing, I can get this to happen 1 in 5 times in a specific part of my game.

Any ideas for a potential solution? The only suggestions I’ve seen so far is this unrelated issue: http://stackoverflow.com/questions/16508912/android-sigsegv-on-nexus-7-in-libskia-near-skcanvasdrawpostext-autodrawloop
In that case it was a threading/synchronization issue. I don’t think that’s the issue in this case since Paint and Canvas are local to createTextBitmapShadowStroke().

Paint synchronization will not fix the issue – it is in the same library, but not the issue you are having. I have several Android applications that use Canvas and libskia to draw 2D graphics (before I found Cococ2d-x) and they were plagued by these issues.

My questions for you are:

#1 - you say ‘happen 1 in 5 times’ what is that specific part of the game doing? is it interacting with the Android Activity lifecycle?

#2 - what device and what OS version.

I see… we’ll that sucks =/

  1. I’m fairly certain that when it happens in my game, it’s happening when I call CCLabelTTF->setString() - Unfortunately the stacktrace isn’t reaching my code for some reason (maybe because of the JNI?). Nothing at that point is messing with the activity lifecycle.

  2. I can get this to happen on any device I test on (if I’m patient enough), but I’ve had the most luck on the following emulator: Level 4.3, 800x480, ARM

Note that this bug is mostly (90%) fixed in Android 4.4

haha… i’ll feel better about that when 90% of people have Android 4.4 =]

hey,

So I tested some more and have been able to narrow it down to a specific line of code:
Cocos2dxBitmap.createTextBitmapShadowStroke(…)
{

// signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) occurs here
final TextProperty textProperty = Cocos2dxBitmap.computeTextProperty(pString, pWidth, pHeight, paint);

}

I used system outs and stack traces and I’m pretty sure it’s happening here via the call to setString() in CCLabelTTF. Not sure if this info helps at all, but maybe there’s a workaround to this method…

Oh woops, I forgot to drill into where in computeTextProperty(). I’ll do that next.

Ok,
Narrowed it down to:

Cocos2dxBitmap.splitString(...)
{
...
pPaint.getFontMetricsInt() // crash occurs here
...
}

The relevant part of the stack trace for this was:

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 002a3127
Stack frame #00  pc 0000fc00  /system/lib/libc.so (dlmalloc+1731)
Stack frame #01  pc 0000d9ab  /system/lib/libc.so (malloc+10)
Stack frame #02  pc 00124010  /system/lib/libskia.so (sk_malloc_flags(unsigned int, unsigned int)+8)
Stack frame #03  pc 00090158  /system/lib/libskia.so (SkChunkAlloc::newBlock(unsigned int, SkChunkAlloc::AllocFailType)+36)
Stack frame #04  pc 000901c8  /system/lib/libskia.so (SkChunkAlloc::alloc(unsigned int, SkChunkAlloc::AllocFailType)+48)
Stack frame #05  pc 000a2374  /system/lib/libskia.so (SkGlyphCache::lookupMetrics(unsigned int, SkGlyphCache::MetricsType)+216)
Stack frame #06  pc 000a2534  /system/lib/libskia.so (SkGlyphCache::getGlyphIDMetrics(unsigned short)+56)
Stack frame #07  pc 000ae52c  /system/lib/libskia.so (SkPaint::getTextWidths(void const*, unsigned int, float*, SkRect*) const+272)
Stack frame #08  pc 00075e4f  /system/lib/libandroid_runtime.so
Stack frame #09  pc 00026d04  /system/lib/libharfbuzz_ng.so
Stack frame #10  pc 0000cd60  /system/lib/libharfbuzz_ng.so (hb_shape_plan_execute+208)
Stack frame #11  pc 0000c728  /system/lib/libharfbuzz_ng.so (hb_shape_full+80)
Stack frame #12  pc 0000c760  /system/lib/libharfbuzz_ng.so (hb_shape+16)
Stack frame #13  pc 0007b6ef  /system/lib/libandroid_runtime.so (android::TextLayoutShaper::shapeFontRun(SkPaint const*)+202)
Stack frame #14  pc 0007b7d1  /system/lib/libandroid_runtime.so (android::TextLayoutShaper::computeRunValues(SkPaint const*, unsigned short const*, unsigned int, unsigned int, unsigned int, bool, android::Vector<float>*, float*, android::Vector<unsigned short>*, android::Vector<float>*)+210)
Stack frame #15  pc 0007ba8b  /system/lib/libandroid_runtime.so (android::TextLayoutShaper::computeValues(SkPaint const*, unsigned short const*, unsigned int, unsigned int, unsigned int, int, android::Vector<float>*, float*, android::Vector<unsigned short>*, android::Vector<float>*)+422)
Stack frame #16  pc 0007bb31  /system/lib/libandroid_runtime.so (android::TextLayoutShaper::computeValues(android::TextLayoutValue*, SkPaint const*, unsigned short const*, unsigned int, unsigned int, unsigned int, int)+44)
Stack frame #17  pc 0007bfef  /system/lib/libandroid_runtime.so (android::TextLayoutCache::getValue(SkPaint const*, unsigned short const*, int, int, int, int)+274)
Stack frame #18  pc 0007c313  /system/lib/libandroid_runtime.so (android::TextLayoutEngine::getValue(SkPaint const*, unsigned short const*, int, int, int, int)+34)
Stack frame #19  pc 0007ac27  /system/lib/libandroid_runtime.so (android::TextLayout::getTextRunAdvances(SkPaint*, unsigned short const*, int, int, int, int, float*, float*)+42)

I’m not getting this crash in my application, but I also avoid the evils of CCLabelTTF in 100% of my application.

I haven’t looked at the code yet, but it is possible that pPaint is part of the problem, it can be very difficult to keep paints correctly synchronized for libskia.

Also, libskia is buggy as hell, so …

That’s a good point - I was thinking of switching everything over to BMFont.
But before I do that, I think I’ll tinker a bit with pPaint and see if I can add some helpful synchronization or something…

yuck… i just want to publish my game already!