gpt4 book ai didi

unity3d - Unity:尝试复制 `mesh`时构建崩溃

转载 作者:行者123 更新时间:2023-12-03 16:59:49 27 4
gpt4 key购买 nike

这段代码在Unity编辑器中可以正常工作:

MeshFilter meshFilter = GetComponent<MeshFilter>();
MeshFilter newFilter = visuals.AddComponent<MeshFilter>();
newFilter.mesh = meshFilter.mesh; // [crashes here]

但是在作为Build运行时在第三行崩溃。

我发现了一个 question似乎非常相似,但是它没有提供任何解释为什么它在Build中崩溃但在编辑器中没有崩溃。就我而言,我通过使用 sharedMesh属性而不是 mesh修复了它,但仍然对崩溃原因一无所知。有任何想法吗?

编辑:
错误文字:

Read from location 0000000000000218 caused an access violation.



调用堆栈以:

0x0000016FE7F431C4 (Assembly-CSharp) .runtime_invoke_void__this___object() 0x00007FFC0663BBCB (mono-2.0-bdwgc) mono_get_runtime_build_info 0x00007FFC065C2252 (mono-2.0-bdwgc) mono_perfcounters_init 0x00007FFC065CB25F (mono-2.0-bdwgc) mono_runtime_invoke 0x00007FFC07DBC6FD (UnityPlayer) UnityMain 0x00007FFC07DB9441 (UnityPlayer) UnityMain 0x00007FFC07D9E545 (UnityPlayer) UnityMain 0x00007FFC0748BACF (UnityPlayer) UnityMain 0x00007FFC07EF2559 (UnityPlayer) UnityMain 0x00007FFC07EF2172 (UnityPlayer) UnityMain 0x00007FFC07D10E99 (UnityPlayer) UnityMain 0x00007FFC07D0CC44 (UnityPlayer) UnityMain 0x00007FFC07A8C157 (UnityPlayer) UnityMain 0x00007FFC07A8C225 (UnityPlayer) UnityMain 0x00007FFC07A8F92F (UnityPlayer) UnityMain 0x00007FFC073DF022 (UnityPlayer) PAL_Memory_Free 0x00007FFC073DD82A (UnityPlayer) PAL_Memory_Free 0x00007FFC073E1F59 (UnityPlayer) PAL_Memory_Free 0x00007FFC073E3BDB (UnityPlayer) UnityMain ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF6865A11F2) 0x00007FF6865A11F2 (ToyTanks) (function-name not available) 0x00007FFC8B414034 (KERNEL32) BaseThreadInitThunk 0x00007FFC8BB63691 (ntdll) RtlUserThreadStart



error.log文件中。

最佳答案

According to Unity's documentation:

If a mesh is assigned to the mesh filter already, then first query of mesh property will create a duplicate of it, and this copy will be returned. Further queries of mesh property will return this duplicated mesh instance. Once mesh property is queried, link to the original shared mesh is lost and MeshFilter.sharedMesh property becomes an alias to mesh. If you want to avoid this automatic mesh duplication, use MeshFilter.sharedMesh instead.



对于第一行代码,请尝试执行此操作。
Mesh mesh = GetComponent<MeshFilter>().sharedMesh;

关于unity3d - Unity:尝试复制 `mesh`时构建崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57664471/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com