

unity native crash —— 横竖屏切换导致的crash
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.

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

一通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/我要说话
☞ 参与评论我要说话
Recommend
-
110
-
62
横竖都是死
-
45
关于横竖屏适配,有一句说一句,坑挺深的。其实在我理解上,只要明白以下几点,横竖屏处理上并不是问题。
-
15
Activity横竖屏切换时先看到横屏/竖屏再变换回竖屏/横屏 ...
-
9
横竖屏切换中的界面设计与体验提升 之前一周朦朦胧胧的过掉了,想来也没什么可回忆的。这是一种不坏的状态,就像每天早上莫名的空洞,它们都代表着生活和工作里至少还没有很坏...
-
8
Fragment和Activity生命周期以及横竖屏切换对生命周期的影响 – Android开发中文站你的位置:Android开发中文站 > Android开发 >
-
16
健身博主,横竖赚钱健身博主,横竖赚钱 2021-09-17
-
7
Activity的跳转、横竖屏切换的生命周期 – Android开发中文站你的位置:Android开发中文站 > Android开发 >
-
6
绝了!也被治愈了!黄海为《入殓师》设计的新海报,横竖都好看! 《入殓师》 /
-
10
unity android 子线程中调用JNI导致的 crash 作者: 邹成卓 2023-03-23 15:59:02 分类:
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK