6

unity native crash —— 横竖屏切换导致的crash

 1 year ago
source link: https://www.zoucz.com/blog/2022/11/30/66788390-70bc-11ed-9fa0-5dbc93f9d3ee/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

unity native crash —— 横竖屏切换导致的crash

作者: 邹成卓 2022-11-30 22:36:39 分类: unity3d

标签: unity3d

评论数:

写了一个 demo 应用,横竖屏切换时应用必然 crash 在 libunity.so 中。
分析原因,看不出任何端倪。

image.png
我要说话

一通google,受 https://blog.csdn.net/ximsfei/article/details/40518727 这篇文章启发,有可能是 activity 重建,引起的依赖 activity 存在的 unityplayer 内部的错误。
在 AndroidManifest.xml 中加上下面的配置以避免 activity 重建。
我要说话

android:configChanges="mcc|mnc|orientation|screenSize"

我要说话

再次试验,果然不再 crash 了。 我要说话

思考,为什么 activity 重建会引起 crash 呢? 应该跟随生命周期才对啊。 我要说话

一通排查,发现 unity 的 destory 没有绑定到 activity 的 destory 生命周期上。
给加上:
我要说话

@Override
protected void onDestroy() {
super.onDestroy();
if(this.vhSDK!=null){
this.vhSDK.destroy();
}
}

我要说话

重试,没有再 crash,即使去掉 android:configChanges 配置也不会再 crash。 我要说话

原因很简单,但是从排查问题的过程来看,属于怎么开脑洞也想不出的问题 —— 要么疯狂 google ,要么研究 unity 源码。故此记录一下,以供后人 google。我要说话

本文链接:https://www.zoucz.com/blog/2022/11/30/66788390-70bc-11ed-9fa0-5dbc93f9d3ee/我要说话

☞ 参与评论我要说话


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK