Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 ViewCacheStuffer 自定义弹幕样式偶现空指针错误 #306

Open
mzw1004 opened this issue May 23, 2017 · 11 comments
Open

使用 ViewCacheStuffer 自定义弹幕样式偶现空指针错误 #306

mzw1004 opened this issue May 23, 2017 · 11 comments

Comments

@mzw1004
Copy link

mzw1004 commented May 23, 2017

自定义布局中使用了 TextView ,在 workerthread 中进行 measure 时,会有概率出现空指针异常,版本为 0.8.3 ,错误日志如下:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.text.Layout.getLineCount()' on a null object reference
at android.widget.TextView.onMeasure(TextView.java:7312)
at android.view.View.measure(View.java:18948)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5976)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1486)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1129)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:649)
at android.view.View.measure(View.java:18948)
at master.flame.danmaku.danmaku.model.android.ViewCacheStuffer$ViewHolder.measure(ViewCacheStuffer.java:28)
at master.flame.danmaku.danmaku.model.android.ViewCacheStuffer.measure(ViewCacheStuffer.java:85)
at master.flame.danmaku.danmaku.model.android.AndroidDisplayer.measure(AndroidDisplayer.java:2526)
at master.flame.danmaku.danmaku.model.BaseDanmaku.measure(BaseDanmaku.java:235)
at master.flame.danmaku.danmaku.model.R2LDanmaku.measure(R2LDanmaku.java:113)
at master.flame.danmaku.controller.CacheManagingDrawTask$CacheManager$CacheHandler.a(CacheManagingDrawTask.java:865)
at master.flame.danmaku.controller.CacheManagingDrawTask$CacheManager$CacheHandler.a(CacheManagingDrawTask.java:939)
at master.flame.danmaku.controller.CacheManagingDrawTask$CacheManager$CacheHandler.handleMessage(CacheManagingDrawTask.java:550)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.os.HandlerThread.run(HandlerThread.java:61)
@zhangxq
Copy link

zhangxq commented Aug 25, 2017

同学,我也遇到同样的问题,请问你解决了吗?如何解决的?谢谢

@mzw1004
Copy link
Author

mzw1004 commented Aug 25, 2017

我放弃使用 ViewCacheStuffer 了,最后用自定义的 BaseCacheStuffer

@zhangxq
Copy link

zhangxq commented Aug 25, 2017

哦,我刚想到可以重写ViewCacheStuffer的measure方法,自己做处理,比如加异常捕捉。

@chaichuanfa
Copy link

v0.9.12依然有这个问题,关注中

@pys200603027
Copy link

这个问题解决了嘛?

@zourb
Copy link

zourb commented Feb 26, 2018

这个问题是必现吗,有复现步骤吗

@mzw1004
Copy link
Author

mzw1004 commented Feb 26, 2018

@zourb 印象中不是必现,多添加几条弹幕会有概率出现。

@erleizh
Copy link

erleizh commented Mar 29, 2018

我也发现了

@jianglinair
Copy link

自定义 ViewHolder 继承 ViewCacheStuffer.ViewHolder 可以保持不崩,但崩溃原因没找到。代码如下:

    public static class MyViewHolder extends ViewCacheStuffer.ViewHolder {

        private final View mItemView;
        private final GradientTextView mGtvText;

        public MyViewHolder (View itemView) {
            super(itemView);
            mItemView = itemView;
            mGtvText = itemView.findViewById(R.id.gtv_danmaku_normal);
        }

        @Override
        public void measure(int widthMeasureSpec, int heightMeasureSpec) {
            try {
                super.measure(widthMeasureSpec, heightMeasureSpec);
            } catch (Exception e) {
                Log.d("[jianglin]", "MyViewHolder.measure: CRASH!");
                Log.d("[jianglin]", "MyViewHolder.measure: " + e.getMessage());
            }
        }
    }

@qinweiforandroid
Copy link

qinweiforandroid commented Mar 2, 2020

@jiangzhuoyan1984

你有没有发现有的时候会出现测量失败 System.err 的消息, 导致界面显示问题

@wygsqsj
Copy link

wygsqsj commented Jul 25, 2023

目前会在安卓12/13的机器上崩在系统底层,不知道是什么原因导致的
#00 pc 0000000000054070 /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) [arm64-v8a::25eadd32a5b6753e7e58e01ae8014530]
2
#1 pc 00000000000429c4 /apex/com.android.runtime/lib64/bionic/libc.so (scudo::die()+8) [arm64-v8a::25eadd32a5b6753e7e58e01ae8014530]
3
#2 pc 0000000000043070 /apex/com.android.runtime/lib64/bionic/libc.so (scudo::ScopedErrorReport::~ScopedErrorReport()+32) [arm64-v8a::25eadd32a5b6753e7e58e01ae8014530]
4
#3 pc 00000000000433d0 /apex/com.android.runtime/lib64/bionic/libc.so (scudo::reportInvalidChunkState(scudo::AllocatorAction, void*)+116) [arm64-v8a::25eadd32a5b6753e7e58e01ae8014530]
5
#4 pc 0000000000044bf0 /apex/com.android.runtime/lib64/bionic/libc.so (scudo::Allocator<scudo::AndroidConfig, &(scudo_malloc_postinit)>::deallocate(void*, scudo::Chunk::Origin, unsigned long, unsigned long)+308) [arm64-v8a::25eadd32a5b6753e7e58e01ae8014530]
6
#5 pc 0000000000049de8 /system/lib64/libminikin.so (minikin::MeasuredData::boringLayoutUseMeasuredDataDoFLayout(minikin::U16StringPiece const&, float, bool, bool, bool)+164) [arm64-v8a::38ab8f36a7547b3d7bea60edded5d114]
7
#6 pc 0000000000223470 /system/lib64/libhwui.so [arm64-v8a::fe97291d2f12507982da13e8bd49868a]
8
#7 pc 00000000001f87f4 /system/framework/arm64/boot-framework.oat [arm64-v8a::80d8736761f18d681316a5ad36eacbc9]
9
java:
10
android.graphics.text.MeasuredData.boringLayoutUseMeasuredDataDoFLayout(MeasuredData.java:119)
11
android.graphics.Paint.boringLayoutUseMeasuredDataDoFLayout(Paint.java:3525)
12
android.text.BoringLayout.isBoring(BoringLayout.java:637)
13
android.widget.TextView.onMeasure(TextView.java:10231)
14
androidx.appcompat.widget.AppCompatTextView.onMeasure(TbsSdkJava:2)
15
android.view.View.measure(View.java:26980)
16
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7259)
17
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1580)
18
android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1211)
19
android.widget.LinearLayout.onMeasure(LinearLayout.java:730)
20
android.view.View.measure(View.java:26980)
21
master.flame.danmaku.danmaku.model.android.k$a.e(TbsSdkJava:1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants