ikew0ng / SwipeBackLayout

An Android library that help you to build app with swipe back gesture.
Apache License 2.0
6.12k stars 1.4k forks source link

java.lang.StackOverflowError #29

Closed jiahui90 closed 10 years ago

jiahui90 commented 10 years ago

java.lang.StackOverflowError at android.text.Styled.measureText(Styled.java:454) at android.text.Layout.measureText(Layout.java:1970) at android.text.Layout.getLineMax(Layout.java:912) at android.text.Layout.draw(Layout.java:414) at android.text.BoringLayout.draw(BoringLayout.java:365) at android.widget.TextView.onDraw(TextView.java:4431) at android.view.View.draw(View.java:6880) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.buildDrawingCache(View.java:6640) at android.view.View.getDrawingCache(View.java:6428) at android.view.ViewGroup.drawChild(ViewGroup.java:1571) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.widget.AbsListView.dispatchDraw(AbsListView.java:1666) at android.widget.ListView.dispatchDraw(ListView.java:3215) at android.view.View.draw(View.java:6986) at android.widget.AbsListView.draw(AbsListView.java:3048) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.support.v4.view.ViewPager.draw(ViewPager.java:1259) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.widget.FrameLayout.draw(FrameLayout.java:357) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at me.imid.swipebacklayout.lib.SwipeBackLayout.drawChild(SwipeBackLayout.java:405) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.widget.FrameLayout.draw(FrameLayout.java:357) at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1921) at android.view.ViewRoot.draw(ViewRoot.java:1526) at android.view.ViewRoot.performTraversals(ViewRoot.java:1262) at android.view.ViewRoot.handleMessage(ViewRoot.java:1863) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3687) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) at dalvik.system.NativeStart.main(Native Method)

ikew0ng commented 10 years ago

It doesn't seem to be the problem of SwipebackLayout.

renkangke commented 10 years ago

是有这个问题的,在drawchild时:

java.lang.StackOverflowError at android.text.TextUtils.getChars(TextUtils.java:63) at android.text.Layout$Ellipsizer.getChars(Layout.java:1863) at android.text.TextUtils.getChars(TextUtils.java:69) at android.graphics.Paint.measureText(Paint.java:1068) at android.text.Styled.drawDirectionalRun(Styled.java:267) at android.text.Styled.measureText(Styled.java:430) at android.text.Layout.measureText(Layout.java:1655) at android.text.Layout.getLineMax(Layout.java:689) at android.text.Layout.draw(Layout.java:340) at android.widget.TextView.onDraw(TextView.java:4173) at android.view.View.draw(View.java:6880) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.widget.AbsListView.dispatchDraw(AbsListView.java:1537) at android.view.View.draw(View.java:6986) at android.widget.AbsListView.draw(AbsListView.java:2684) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.view.View.buildDrawingCache(View.java:6642) at android.view.View.getDrawingCache(View.java:6428) at android.view.ViewGroup.drawChild(ViewGroup.java:1571) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.widget.AbsListView.dispatchDraw(AbsListView.java:1537) at android.view.View.draw(View.java:6883) at android.widget.AbsListView.draw(AbsListView.java:2684) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:769) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.widget.FrameLayout.draw(FrameLayout.java:357) at android.view.ViewGroup.drawChild(ViewGroup.java:1646) at me.imid.swipebacklayout.lib.SwipeBackLayout.drawChild(SwipeBackLayout.java:392) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.ViewGroup.drawChild(ViewGroup.java:1644) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) at android.view.View.draw(View.java:6883) at android.widget.FrameLayout.draw(FrameLayout.java:357) at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1943) at android.view.ViewRoot.draw(ViewRoot.java:1522) at android.view.ViewRoot.performTraversals(ViewRoot.java:1258) at android.view.ViewRoot.handleMessage(ViewRoot.java:1859) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method)

renkangke commented 10 years ago

是在低端机手机内存很低的时候,不断绘制会内存溢出

renkangke commented 10 years ago

SwipeBackLayout中此方法会不断递归,当页面层次过多时,在低端手机,会导致StackOverflowError

@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final boolean drawContent = child == mContentView; drawShadow(canvas, child);

    boolean ret = super.drawChild(canvas, child, drawingTime);
    if (mScrimOpacity > 0 && drawContent
            && mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) {
        drawScrim(canvas, child);
    }
    return ret;
}
ikew0ng commented 10 years ago

有解决方案嘛 :)

ikew0ng commented 10 years ago

我查了一下,没能发现很好的方案, @conquerandroid 有思路吗?

renkangke commented 10 years ago

这里必须使用递归的话,在布局时减少嵌套层次能缓解这个问题(比如用RelativeLayout),但无法根治

ikew0ng commented 10 years ago