#Crash in EntityManager.CopyEntitiesFrom

1 messages · Page 1 of 1 (latest)

trim iron
#

Been struggling with figuring out this crash in my saving system. The specific part that is having issues is the CopyEntitiesFrom call before the smiley.

var builder = new EntityQueryBuilder(Allocator.Temp);
builder
    .WithAny<SaveTag, Prefab>()
    .WithOptions(EntityQueryOptions.IncludePrefab | EntityQueryOptions.IncludePrefab);
using var saveQuery = builder.Build(originalEm);
Debug.Log($"Completing savequery dependency");
saveQuery.CompleteDependency();
Debug.Log($"Getting entity array");
using var entities = saveQuery.ToEntityArray(Allocator.Temp);
Debug.Log($"Copying entities");
entityManager.CopyEntitiesFrom(originalEm, entities);
Debug.Log($":)");

With the error:

0x00007FF9B290C0A8 (lib_burst_generated) [C:\build\output\unity\unity\Runtime\Jobs\Managed\IJobParallelFor.cs:47] Unity.Jobs.IJobParallelForExtensions.ParallelForJobStruct`1<Unity.Entities.EntityManager.RemapChunksFilteredJob>.Execute(ref Unity.Entities.EntityManager.RemapChunksFilteredJob jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) -> void_7435d70d723590c51e89202ae2f9be71 from UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 
0x00007FF9B290B376 (lib_burst_generated) 133cdc8adea96c01df559b08afa2ef56_avx2
0x00007FF9B2982217 (lib_burst_generated) 133cdc8adea96c01df559b08afa2ef56

I haven't managed to find a 100% consistent repro, so at first I thought the issue was caused by some other job running at the same time that I wasn't completing the dependency for, but I've made sure to complete all dependencies and it still happens. I've also tried running the following code on both entity managers before calling the code above:

entityManager.ExclusiveEntityTransactionDependency.Complete();
entityManager.EndExclusiveEntityTransaction();
entityManager.CompleteAllTrackedJobs();

Is there anything I can do to get a better error or disable burst on the job?

atomic steeple
#

Embed the package and remove BurstCompile from RemapChunksFilteredJob

#

Or just make the change on a recent 2022.3/6000.0 release since they don’t immediately toss modifications to PackageCache packages

trim iron
#

Ah, true, not sure why I didn't think of that.

trim iron
#

Huh, so that somehow made the logging worse. Now it only outputs the symbol-searchpath, and is completely blank after "Outputting Stack Trace". Also was a lot more difficult to make the crash happen, strangely enough.

#

Time to put down a ton of Debug.Logs inside the job, lol

trim iron
#

Okay, progress, it crashes specifically on this part when index is 43 (probably arbritrary which index it is):

EntityRemapUtility.PatchEntities(dstArchetype->ScalarEntityPatches + 1,
dstArchetype->ScalarEntityPatchCount - 1, dstArchetype->BufferEntityPatches,
dstArchetype->BufferEntityPatchCount, chunk.Buffer, entityCount, ref entityRemapping);
#

Stacktrace also worked this time, I probably should've turned of il2cpp though

0x00007FF98C2CD376 (GameAssembly) [C:\source\LB\Library\Bee\artifacts\WinPlayerBuildProgram\il2cppOutput\cpp\Unity.Entities__6.cpp:22745] EntityRemapUtility_RemapEntity_m7F96C1410C03DA7153372B16DEF832834544405D 
0x00007FF98C2CCD6F (GameAssembly) [C:\source\LB\Library\Bee\artifacts\WinPlayerBuildProgram\il2cppOutput\cpp\Unity.Entities__6.cpp:24064] EntityRemapUtility_PatchEntities_m4CFF65288F4F91A11C75384A48B656310840F8D2 
0x00007FF98C2CFE8D (GameAssembly) [C:\source\LB\Library\Bee\artifacts\WinPlayerBuildProgram\il2cppOutput\cpp\Unity.Entities__6.cpp:18825] RemapChunksFilteredJob_Execute_m8FF821F388E586B2666BD90DC8F4A1D9FBABE268 
0x00007FF98AB64ADA (GameAssembly) [C:\source\LB\Library\Bee\artifacts\WinPlayerBuildProgram\il2cppOutput\cpp\Generics__200.cpp:13056] ParallelForJobStruct_1_Execute_m53F349BC479D7F7032222AA25EFF575B9350B1AD_gshared 
0x00007FF9896610C9 (GameAssembly) [C:\source\LB\Library\Bee\artifacts\WinPlayerBuildProgram\il2cppOutput\cpp\Generics__104.cpp:27192] ExecuteJobFunction_Invoke_mF91EF9501D3C5B5F7F2A206AEC2B8DE0BD3A4197_OpenStatic 
0x00007FF989A8891E (GameAssembly) [C:\source\LB\Library\Bee\artifacts\WinPlayerBuildProgram\il2cppOutput\cpp\Il2CppInvokerTable.cpp:116781] RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915_VoidU2A_t104EAEFBD2D237A8C29618913DA9B4D99355E965_IntPtr_t_IntPtr_t_VoidU2A_t104EAEFBD2D237A8C29618913DA9B4D99355E965_Int32_t680FF22E76F6EFAD4375103CBBFFA0421349384C 
0x00007FF989C10346 (GameAssembly) [C:\Unity\2023.2.0b17\Editor\Data\il2cpp\libil2cpp\vm\Runtime.cpp:623] il2cpp::vm::Runtime::InvokeWithThrow 
0x00007FF989C0FDE9 (GameAssembly) [C:\Unity\2023.2.0b17\Editor\Data\il2cpp\libil2cpp\vm\Runtime.cpp:608] il2cpp::vm::Runtime::Invoke 
trim iron
#

I have an idea of what component's causing it, since it's a pretty wack one

#

OH! I managed to reproduce it in editor for once! Though at serialize world instead, but still in RemapEntity:

NullReferenceException: Object reference not set to an instance of an object
Unity.Entities.EntityRemapUtility.RemapEntity (Unity.Entities.EntityRemapUtility+EntityRemapInfo* remapping, Unity.Entities.Entity source) (at C:/source/com.unity.entities@1.2.1/Unity.Entities/EntityRemapUtility.cs:78)
Unity.Entities.EntityRemapUtility.RemapEntity (...) (at C:/source/com.unity.entities@1.2.1/Unity.Entities/EntityRemapUtility.cs:67)
Unity.Entities.EntityRemapUtility.PatchEntities (...) (at C:/source/com.unity.entities@1.2.1/Unity.Entities/EntityRemapUtility.cs:467)
Unity.Entities.Serialization.SerializeUtility.WriteChunks (...) (at C:/source/com.unity.entities@1.2.1/Unity.Entities/Serialization/SerializeUtility.cs:1439)
Unity.Entities.Serialization.SerializeUtility.SerializeWorldInternal (...)

Had to shorten it a bit to fit it in a message

#

Ah, yeah, I think I know why it's happening now. I have a manually made union type, and it can contain an entity reference

#

But since the field shares type with a bunch of other fields, it might also not be an entity reference

#

so obviously when serializing there's no way for the remapper to know if it should remap it or not

fossil otter
#

that certainly sounds like a really bad idea

trim iron
#

I could extract the Entity reference to be shared between all the variants. It'd be 8 bytes wasted per entry, but not all that bad