渲染线程发生SIGABRT错误

15

我在使用共享元素转换来实现Activity之间的过渡时,在安卓8.1系统以及谷歌设备(如Pixel、Pixel 2、Nexus 6P等)上遇到了本机崩溃问题:

pid: 20499, tid: 22683, name: RenderThread  >>> [APPNAME] <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'sp<> assignment detected data race'
    x0   0000000000000000  x1   000000000000589b  x2   0000000000000006  x3   0000000000000008
    x4   0700007411003135  x5   0700007411003135  x6   0700007411003135  x7   3531ffffffffffff
    x8   0000000000000083  x9   0000000010000000  x10  0000007214bf4ca0  x11  0000000000000001
    x12  0000007214bf4dc0  x13  ffffffffffffffff  x14  ffffffffffff0000  x15  ffffffffffffffff
    x16  0000005c0f077fa8  x17  00000072b09c752c  x18  0000000000000008  x19  0000000000005013
    x20  000000000000589b  x21  0000000000000083  x22  00000072249f1f40  x23  00000072249f1f58
    x24  0000007214717590  x25  00000072248393a0  x26  00000072118d9220  x27  0000007214bf5350
    x28  0000007214bf5300  x29  0000007214bf4ce0  x30  00000072b097c760
    sp   0000007214bf4ca0  pc   00000072b097c788  pstate 0000000060000000
backtrace:
    #00 pc 000000000001d788  /system/lib64/libc.so (abort+120)
    #01 pc 0000000000007f08  /system/lib64/liblog.so (__android_log_assert+296)
    #02 pc 0000000000010af4  /system/lib64/libutils.so (android::sp_report_race()+28)
    #03 pc 00000000000fdd08  /system/lib64/libandroid_runtime.so (android::RootRenderNode::detachAnimators()+320)
    #04 pc 00000000000fbcac  /system/lib64/libandroid_runtime.so (android::AnimationContextBridge::destroy()+24)
    #05 pc 000000000006fbd0  /system/lib64/libhwui.so (android::uirenderer::renderthread::Bridge_destroy(android::uirenderer::renderthread::destroyArgs*)+12)
    #06 pc 00000000000718fc  /system/lib64/libhwui.so (android::uirenderer::renderthread::MethodInvokeRenderTask::run()+24)
    #07 pc 0000000000071c70  /system/lib64/libhwui.so (android::uirenderer::renderthread::SignalingRenderTask::run()+28)
    #08 pc 0000000000072a58  /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+336)
    #09 pc 0000000000011478  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+280)
    #10 pc 00000000000a9814  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+140)
    #11 pc 0000000000067d80  /system/lib64/libc.so (__pthread_start(void*)+36)
    #12 pc 000000000001ec18  /system/lib64/libc.so (__start_thread+68)

如果应用在后台运行,它也会崩溃。我该怎么解决这个问题?似乎只有在启用硬件加速时才会发生,但我确实需要在我的应用程序中启用它。


你发现了什么吗?我得到了以下信息,我认为这与在通知中使用自定义RemoteViews有关。07-28 09:24:00.328 21108-21135 /?A / libc:致命信号6(SIGABRT),代码-6在tid 21135(RenderThread)中,pid 21108(e.tm.free.debug)。 - Ewan
我也遇到了同样的问题,但它发生在Android 6到Android 8.1之间。 - Davide Berra
3
最终,我发现有两个动画同时在运行,所以我不得不稍微修改其中一个动画,以便它们之间不再发生竞争。恐怕这是唯一的解决办法,直到安卓团队修复本地库中的问题。 - darkalbo
我遇到了相同的问题,它是随机发生的。我不知道该如何处理它。 - ene
@ene 这是一个随机事件,因为存在竞态条件:两个动画同时在同一对象上运行。您可以通过禁用或延迟其中一个来解决它(确保它在另一个完成后运行)。 - darkalbo
@darkalbo 你怎么知道有两个动画同时在运行?我尝试在开始动画之前添加以下代码。但是,仍然有很小的概率发生崩溃。 if (mExposureDrawable.isRunning()){ mExposureDrawable.stop(); } mExposureDrawable.start();``` - ene
2个回答

5

我遇到了一个与AnimatedVectorDrawable有关的问题,将其设置为ImageView的背景。基本上,我在recyclerview的不同行中显示相同的动画,但是只使用了一个AnimatedVectorDrawable对象,这导致了崩溃。我通过为每个ViewHolder创建单独的对象来解决了这个问题。


3

有时候在尝试暂停Activity后(或者可能是同时)重新启动AnimatedVectorDrawable的动画循环时,会看到相同的本地堆栈。

作为参考,动画循环如下:

((Animatable2)animatable).registerAnimationCallback(new Animatable2.AnimationCallback() {
    @Override
    public void onAnimationEnd(Drawable drawable) {
        animatable.start();
    }
});

当从应用程序切换时,会记录以下信息:
W/WindowManager: Unable to start animation, surface is null or no children.

接下来是一个与竞态条件相关的类似本地堆栈:

A/DEBUG: backtrace:
A/DEBUG:     #00 pc 0000000000021abc  /system/lib64/libc.so (abort+124)
A/DEBUG:     #01 pc 00000000000080f8  /system/lib64/liblog.so (__android_log_assert+296)
A/DEBUG:     #02 pc 000000000000f26c  /system/lib64/libutils.so (android::sp_report_race()+28)
A/DEBUG:     #03 pc 000000000010d698  /system/lib64/libandroid_runtime.so (android::RootRenderNode::detachAnimators()+320)
A/DEBUG:     #04 pc 000000000010b768  /system/lib64/libandroid_runtime.so (android::AnimationContextBridge::destroy()+24)
A/DEBUG:     #05 pc 00000000005d211c  /system/lib64/libhwui.so (android::uirenderer::renderthread::CanvasContext::destroy()+124)
A/DEBUG:     #06 pc 00000000005d5550  /system/lib64/libhwui.so (std::__1::packaged_task<void ()>::operator()()+88)
A/DEBUG:     #07 pc 00000000005870b0  /system/lib64/libhwui.so (android::uirenderer::WorkQueue::process()+168)
A/DEBUG:     #08 pc 00000000001fd60c  /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+244)
A/DEBUG:     #09 pc 000000000000fb80  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+280)
A/DEBUG:     #10 pc 0000000000083114  /system/lib64/libc.so (__pthread_start(void*)+36)
A/DEBUG:     #11 pc 00000000000233bc  /system/lib64/libc.so (__start_thread+68)

这个做法已经解决了问题 - 它一直应该存在于Activity类中:

@Override
protected void onPause() {
    super.onPause();

    animatable.stop();
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接