Job System并行生成过程网格

问题描述


我正在创建基于体素的游戏。
世界由块组成,每个块包含16x16x16块,对于我正在创建的每个块而言,网格。
我创建了一个ParrarelJob,其中我为块内的每个块编写了网格数据。
对于块的每一侧,都从持久性NativeArray读取顶点,在该数组中我保存了有关顶点,三角形和uvs的信息,然后将它们写入本机列表(我使用list是因为我不知道网格中将有多少个顶点)与AddRange()
MeshVertices.AddRange(vertices);。我需要将属性[[NativeDisableParallelForRestriction]`添加到所有列表中,因为这是说不支持并行写入。在一个由许多块组成的世界中,统一只会崩溃。但是如果只有一个大块统一说:
Invalid memory pointer was detected in ThreadsafeLinearAllocator::Deallocate!
Unity.Collections.LowLevel.Unsafe.UnsafeUtility:Free(Void*,Allocator)
Unity.Collections.AllocatorManager:TryLegacy(Block&) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/AllocatorManager.cs:431)
Unity.Collections.AllocatorManager:Try(Block&) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/AllocatorManager.cs:450)
Unity.Collections.AllocatorManager:Free(AllocatorHandle,Void*,Int32,Int32) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/AllocatorManager.cs:74)
Unity.Collections.AllocatorManager:Free(AllocatorHandle,Void*) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/AllocatorManager.cs:85)
Unity.Collections.LowLevel.Unsafe.UnsafeList:Realloc(Int32,Int32) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/UnsafeList.cs:293)
Unity.Collections.LowLevel.Unsafe.UnsafeList:SetCapacity(Int32,Int32) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/UnsafeList.cs:310)
Unity.Collections.LowLevel.Unsafe.UnsafeList:Resize(Int32,NativeArrayOptions) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/UnsafeList.cs:251)
Unity.Collections.LowLevel.Unsafe.UnsafeList:Resize(Int32,NativeArrayOptions) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/UnsafeList.cs:273)
Unity.Collections.LowLevel.Unsafe.UnsafeList:Add(Int32) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/UnsafeList.cs:422)
Unity.Collections.NativeList`1:Add(Int32&) (at Library/PackageCache/com.unity.collections@0.12.0-preview.13/Unity.Collections/NativeList.cs:293)
Hexcraft.Map.GenerateBlockMeshJob:Execute(Int32) (at Assets/_Project/Scripts/Map/GenerateBlockMeshJob.cs:35)
Unity.Jobs.ParallelForJobStruct`1:Execute(GenerateBlockMeshJob&,IntPtr,JobRanges&,Int32)
Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
Unity.Jobs.JobHandle:Complete()
Hexcraft.Map.Chunk:DrawChunk() (at Assets/_Project/Scripts/Map/Chunk.cs:73)
Hexcraft.Map.World:BuildWorld() (at Assets/_Project/Scripts/Map/World.cs:93)

我认为AddRange与其他工作人员的记忆重叠。
我该如何避免这些类型的错误?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...