Search Unity

Strange exception on `BlobArray` with `yield return`

Discussion in 'Entity Component System' started by quabug, Mar 16, 2020.

  1. quabug

    quabug

    Joined:
    Jul 18, 2015
    Posts:
    66
    Code (CSharp):
    1.     public struct Test
    2.     {
    3.         private BlobArray<int> BlobArray;
    4.      
    5.         public IEnumerable<int> Yield()
    6.         {
    7.             yield return 0;
    8.         }
    9.     }
    This block of code make unity throw an exception and stop compiling in Editor.
    A `return` without `yield` would be fine through.

    Code (csharp):
    1.  
    2. Something went wrong while Post Processing the assembly (EntitiesBT.Runtime.dll) :
    3.  Index was out of range. Must be non-negative and less than the size of the collection.
    4. Parameter name: index
    5.   at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00029] in <437ba245d8404784b9fbab9b439ac908>:0
    6.   at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0
    7.   at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <437ba245d8404784b9fbab9b439ac908>:0
    8.   at Unity.Entities.CodeGen.CecilHelpers.FindBestSequencePointFor (Mono.Cecil.MethodDefinition method, Mono.Cecil.Cil.Instruction instruction) [0x00047] in /Users/quabug/proj/EntitiesBehaviorTree/EntityBehaviorTreeExample/Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.CodeGen/CecilHelpers.cs:73
    9. rError.MakeError (System.String errorCode, System.String messageData, Mono.Cecil.MethodDefinition method, Mono.Cecil.Cil.Instruction instruction) [0x00001] in /Users/quabug/proj/EntitiesBehaviorTree/EntityBehaviorTreeExample/Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.CodeGen/LambdaJobs/UserError.cs:346
    10.   at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.VerifyMethod (Mono.Cecil.MethodDefinition method, System.Collections.Generic.HashSet`1[T] _nonRestrictedTypes) [0x001ee] in /Users/quabug/proj/EntitiesBehaviorTree/EntityBehaviorTreeExample/Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.CodeGen/BlobAssetSafety/BlobAssetSafetyVerifier.cs:137
    11.   at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.AssertNoBlobAssetLeavesBlobAssetStorage () [0x00063] in /Users/quabug/proj/EntitiesBehaviorTree/EntityBehaviorTreeExample/Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.CodeGen/BlobAssetSafety/BlobAssetSafetyVerifier.cs:39
    12.   at Unity.Entities.CodeGen.BlobAssetSafetyVerifier.PostProcessImpl () [0x0000a] in /Users/quabug/proj/EntitiesBehaviorTree/EntityBehaviorTreeExample/Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.CodeGen/BlobAssetSafety/BlobAssetSafetyVerifier.cs:22
    13.   at Unity.Entities.CodeGen.EntitiesILPostProcessor.PostProcess (Mono.Cecil.AssemblyDefinition assemblyDefinition, System.Boolean& madeAChange) [0x00009] in /Users/quabug/proj/EntitiesBehaviorTree/EntityBehaviorTreeExample/Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.CodeGen/EntitiesILPostProcessor.cs:231
    14.   at Unity.Entities.CodeGen.EntitiesILPostProcessors.Process (Unity.CompilationPipeline.Common.ILPostProcessing.ICompiledAssembly compiledAssembly) [0x0004b] in /Users/quabug/proj/EntitiesBehaviorTree/EntityBehaviorTreeExample/Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.CodeGen/EntitiesILPostProcessor.cs:44
    15.   at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.RunILPostProcessors (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.String outputTempPath) [0x0011b] in /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/ILPostProcessing.cs:209
    16.   at UnityEditor.Scripting.ScriptCompilation.ILPostProcessing.PostProcess (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly assembly, System.Collections.Generic.List`1[T] messages, System.String outputTempPath) [0x00061] in /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/ILPostProcessing.cs:99
    17.  
     
    cultureulterior likes this.
  2. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    87
    Hey @quabug.

    It looks like using a yield statement in that method does generate unsafe IL (due to the code that the yield statement generates). We will add a fix to the next version of Entities to generate a valid error. Thanks!
     
    quabug likes this.