Unity3d 移动平台宕机bug 之 ParticleSystemRenderer::UpdateCachedMesh

宕机bug日志分析:

通过logcat观察到的宕机堆栈

案例一

ParticleSystemRenderer::UpdateCachedMesh()atParticleSystemRenderer.cpp:

0x2053c8c:push{r4,r5,r6,r7,lr}

0x2053c8e:add    r7,sp,#0xc

0x2053c90:push.w{r8,r10,r11}

0x2053c94:subsp,#0x8

...

0x2053c9a:mov.w  r10,#0x0

...

0x2053d16:str.w  r10,[sp,#4]

...

0x2053d42:blx0x294c5d8;symbol stubfor:memcpy

0x2053d46:ldr.w  r10,[sp,#4]            ; The game crashes here

0x2053d4a:b0x2053db0;ParticleSystemRenderer::UpdateCachedMesh()+292[inlined]ListElement::GetNext()constatLinkedList.h:71

案例二:

09-29 22:14:48.257 3093-3093/? A/DEBUG:     r0 be2aabb0  r1 00000000  r2 0000000c  r3 00000000

09-29 22:14:48.257 3093-3093/? A/DEBUG:     r4 cc83fc10  r5 cc0ce8d0  r6 be2aabb0  r7 0000000c

09-29 22:14:48.257 3093-3093/? A/DEBUG:     r8 cc83fdac  r9 00000000  sl 00000006  fp 00000000

09-29 22:14:48.257 3093-3093/? A/DEBUG:     ip 80000000  sp eeb72290  lr e0d8111c  pc f6df87cc  cpsr a0010010

09-29 22:14:48.307 3093-3093/? A/DEBUG: backtrace:

09-29 22:14:48.307 3093-3093/? A/DEBUG:     #00 pc 000177cc  /system/lib/

libc.so (__memcpy_base+272)

libunity.so (_ZN22ParticleSystemRenderer16UpdateCachedMeshEv+684)

libunity.so (_ZN18AwakeFromLoadQueue30PersistentManagerAwakeFromLoadEi17AwakeFromLoadMode+176)

libunity.so (_ZN18AwakeFromLoadQueue30PersistentManagerAwakeFromLoadEv+128)

libunity.so (_ZN18LoadSceneOperation21CompleteAwakeSequenceEv+132)

libunity.so (_ZN18LoadSceneOperation25PlayerLoadSceneFromThreadEv+316)

libunity.so (_ZN18LoadSceneOperation19IntegrateMainThreadEv+184)

libunity.so (_ZN14PreloadManager26UpdatePreloadingSingleStepENS_21UpdatePreloadingFlagsEi+388)

libunity.so (_ZN14PreloadManager16UpdatePreloadingEv+328)

libunity.so (_Z10PlayerLoopbbP10IHookEvent+616)

 /data/app/com.funova.metaworld-2/lib/arm/

libunity.so (_Z15UnityPlayerLoopv+880)

libunity.so (_Z12nativeRenderP7_JNIEnvP8_jobject+264)

 2/oat/arm/base.odex (offset 0x22000) (boolean com.unity3d.player.UnityPlayer.nativeRender()+76)

 2/oat/arm/base.odex (offset 0x22000) (boolean com.unity3d.player.UnityPlayer.a(com.unity3d.player


从报错信息字面意思来看,是在渲染过程中,更新缓存的网格信息时,内存拷贝失败,导致宕机。

可以初步判断是mesh这类资源的出的问题,并且是在需要mesh进行内存拷贝的时候。带着这个疑问去搜索了官方资料。

在Models 导入的说明文档中到找到了一个选项:Read/Write Enabled 如果设置为enabled的话,那就可以进行内存拷贝。 文档连接

修复该宕机bug,就是需要把 Read/Write Enabled 勾上选项

Read/Write Enabled 选项说明

Enables the mesh to be written at runtime so you can modify the data; it makes a copy in memory. When this option is turned off, it saves memory since Unity can unload a copy of mesh data in the game. However, if you are scaling or instantiating meshes at runtime with a non-uniform scale, you may have to enable “Read/Write Enabled” in their import settings. The reason is that non-uniform scaling requires the mesh data to be kept in memory. Normally this is detected at build time, but when meshes are scaled or instantiated at runtime you need to set this manually. Otherwise they might not be rendered in game builds correctly. The same applies if you need to create MeshColliders at runtime.

如果导入的mesh需要做 non-uniform scale (不均匀缩放),那就需要进行一次拷贝操作,那么对于mesh导入时,需要设定为可以读写,否者就会出现宕机或渲染的对象不正确的情况。

补充说明,mesh出现这类问题的时候,对MeshColliders也需要做相同的设置操作。

从内存优化角度来说,最好不好在有多份的mesh存在,那样会浪费内存

说明在导入时 Scale Factor 参数的设置会比较重要

Unity’s physics system expects 1 meter in the game world to be 1 unit in the imported file. If you prefer to model at a different scale then you can compensate for it here. Defaults for different 3D packages are as follows .fbx, .max, .jas, .c4d = 0.01, .mb, .ma, .lxo, .dxf, .blend, .dae = 1 .3ds = 0.1

以上说明根据导入mesh的文件的格式,与unity物理系统的之间1m与1个单位的对应关系

尽量在导入时机会做好标准缩放了,那么就不需要在scale 或 instantiating 时进行多份内存拷贝了。 




// 检测工具

public static void CheckFXBReadWriteEnable()

{

string artPath = "Assets/Resourcex/art";

var paths = Directory.GetFiles(artPath, "*.meta", SearchOption.AllDirectories).Where(s => s.ToLower().EndsWith("fbx.meta"));

foreach (string path in paths)

{

using (StreamReader fsRead = new StreamReader(path))

{

int isReadable = 0;

float globalScale = 1f;

while (!fsRead.EndOfStream)

{

string line = fsRead.ReadLine();

if (line.IndexOf("isReadable") != -1)

{

string[] items = line.Split(':');

if (items.Length==2)

{

isReadable = Int32.Parse(items[1]);

}

}

else if (line.IndexOf("globalScale") != -1)

{

string[] items = line.Split(':');

if (items.Length == 2)

{

globalScale = float.Parse(items[1]);

}

}

}

if (globalScale != 1 && isReadable == 0)

{

Debug.LogErrorFormat("import model [ {0} ] scale factor is [{1}] must set read/write enable",

path, globalScale);

}

}

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,943评论 0 0
  • 文/蒙涓 那是我做过最令我难受的梦。 梦境里被蓝色粉刷,印衬出孤凉之意。而蓝色却是我偏爱的颜色。我的四周都有深不见...
    蒙涓阅读 2,166评论 3 6
  • 文人大多都对政治有着天生的抵触,沈从文也不曾试图把文学和政治分离开来。 他只想着借文学的美和善来改造世道良心。他对...
    顽皮的panda阅读 8,481评论 7 3
  • 传统电商即将面临淘汰,新零售将兴起,未来20年是新零售的世界,也是传统电商的退幕,这是马云在去年提出的观点。 传统...
    小程序进行时阅读 5,796评论 0 0
  • 用你的手执笔 画出一片我的天空 我虔诚仰望 光 是你热情的问候 风 是你轻柔的抚摸 雨 是你温和的滋养 云 是你细...
    小rou球变身阅读 3,365评论 0 0