Translate

[Android] signal 6 (SIGABRT) 해결방법




signal 6 에러가 발생을하며 App 이 종료되는 이슈가 있어서 원인분석을 해봤다.




App 이 종료되며 아래와 같은 로그가 발생된다.


Fatal signal 6 (SIGABRT) at 0x000045fd (code=-6), thread 17917 (r.blabla)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Revision: '0'
pid: 17917, tid: 17917, name: r.blabla  >>> kr.or.blabla <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
    r0 00000000  r1 000045fd  r2 00000006  r3 00000000
    r4 00000006  r5 0000000c  r6 000045fd  r7 0000010c

...


backtrace:
    #00  pc 000220dc  /system/lib/libc.so (tgkill+12)
    #01  pc 00013131  /system/lib/libc.so (pthread_kill+48)

...

    #27  pc 0000105b  /system/bin/app_process
    #28  pc 0000e49b  /system/lib/libc.so (__libc_init+50)
    #29  pc 00000d7c  /system/bin/app_process
    at android.graphics.Typeface.nativeCreateFromAsset(Native Method)
    at android.graphics.Typeface.createFromAsset(Typeface.java:+4)
    at kr.or.blabla.ui.ProductCustomTV.applyTypeface(ProductCustomTV.java:+10)
    at kr.or.blabla.ui.ProductCustomTV.applyTypeface(ProductCustomTV.java:+22)
    at kr.or.blabla.ui.ProductCustomTV.<init>(ProductCustomTV.java:+6)
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:+20)
    at android.view.LayoutInflater.createView(LayoutInflater.java:+168)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:+148)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:+224)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:+246)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:+498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:+24)
    at kr.or.blabla.left.CategoryAdapter.getView(CategoryAdapter.java:+16)
    at android.widget.AbsListView.obtainView(AbsListView.java:+284)
    at android.widget.GridView.onMeasure(GridView.java:+282)
    at kr.or.blabla.util.ExpandableHeightGridView.onMeasure(ExpandableHeightGridView.java:+30)
    at android.view.View.measure(View.java:+274)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:+84)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:+12)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:+482)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:+10)
    at android.view.View.measure(View.java:+274)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:+84)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:+12)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:+482)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:+10)
    at android.view.View.measure(View.java:+274)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:+84)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:+12)
    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:+914)








원인을 알고나니 위의 로그가 확실히 보였지만
App이 종료되며 아래와 같은 로그가 같이 발생한 경우가 있었다.


mmap(0,1665467) failed: Out of memory
create map from entry failed
java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:195)
at android.graphics.Typeface.createFromAsset(Typeface.java:169)
at kr.or.blabla.ui.ProductCustomTV.applyTypeface(ProductCustomTV.java:36)
at kr.or.blabla.ui.ProductCustomTV.applyTypeface(ProductCustomTV.java:29)
at kr.or.blabla.ui.ProductCustomTV.<init>(ProductCustomTV.java:18)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)





전체로그 다운받기 => Link




PS.
생성된 로그를 가지고 분석 시 아래와 같은 원인&해결방법을 알아내었다.
로그에 따라 원인&해결방법이 달라질 수 있다.




원인

Custom Font 를 사용하면서 Font Resource 를 재사용하지 않아서 발생한 문제였다.
(로그 분석시..)






해결방법
1004lucifer
Custom Font 의 Resource 를 재사용 하도록 수정 후에는 증상이 발생하지 않았다.




기존 소스

public class HansalimCustomTV extends TextView {

 public HansalimCustomTV(Context context) {
  super(context);
 }

 public HansalimCustomTV(Context context, AttributeSet attrs) {
  super(context, attrs);
  applyTypeface(context, attrs);
 }

 public HansalimCustomTV(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  applyTypeface(context, attrs);
 }

 private void applyTypeface(Context context, AttributeSet attrs) {
  TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.HansalimCustomTV);
  String typefaceName = arr.getString(R.styleable.HansalimCustomTV_typeface);
  applyTypeface(context, typefaceName);
  arr.recycle();
 }

 public boolean applyTypeface(Context context, String asset) {
  Typeface typeface = null;
  try {
   typeface = Typeface.createFromAsset(context.getAssets(), asset);
  } catch (Exception e) {
   e.printStackTrace();
   return false;
  }
  setTypeface(typeface);
  return true;
 }
}




수정 후

public class HansalimCustomTV extends TextView {
 
 private static Typeface typeface;

 public HansalimCustomTV(Context context) {
  super(context);
 }

 public HansalimCustomTV(Context context, AttributeSet attrs) {
  super(context, attrs);
  applyTypeface(context, attrs);
 }

 public HansalimCustomTV(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  applyTypeface(context, attrs);
 }

 private void applyTypeface(Context context, AttributeSet attrs) {
  TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.HansalimCustomTV);
  String typefaceName = arr.getString(R.styleable.HansalimCustomTV_typeface);
  applyTypeface(context, typefaceName);
  arr.recycle();
 }

 public boolean applyTypeface(Context context, String asset) {
  
  try {
   if (typeface == null) {
    typeface = Typeface.createFromAsset(context.getAssets(), asset);
   }
  } catch (Exception e) {
   e.printStackTrace();
   return false;
  }
  setTypeface(typeface);
  return true;
 }
}




참조:
http://stackoverflow.com/questions/23977114/custom-font-in-android-leaking-memory
https://code.google.com/p/android/issues/detail?id=9904
http://blog.csdn.net/qlx2522/article/details/47101947


댓글