Search Unity

BadImageFormatException: Method with open type while not compiling gshared

Discussion in 'Entity Component System' started by alexandre-fiset, Nov 25, 2019.

  1. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    715
    I'm trying to migrate my AnimatorSystem to the new without burst JobComponentSystem, and while writing the code was quite quick and compiled just fine, turns out it doesn't work at runtime. I get the following error: BadImageFormatException: Method with open type while not compiling gshared

    I believe it may be due to the fact that I have a generic system that I override. The error is thrown in the implementations of the following code:

    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Jobs;
    3. using UnityEngine;
    4.  
    5. namespace Parabole.AnimatorSystems
    6. {
    7.     [UpdateInGroup(typeof(PresentationSystemGroup))]
    8.     [AlwaysSynchronizeSystem]
    9.     public abstract class SetBufferElementSystem<TBufferElementData> : JobComponentSystem
    10.         where TBufferElementData : struct, IBufferElementData
    11.     {
    12.         private EntityQueryDesc queryDesc;
    13.         private EntityQuery query;
    14.  
    15.         private bool hasInitialized = false;
    16.  
    17.         protected override void OnCreate()
    18.         {
    19.             queryDesc = new EntityQueryDesc
    20.             {
    21.                 All = new[]
    22.                 {
    23.                     ComponentType.ReadOnly<DotsAnimator>(),
    24.                     ComponentType.ReadWrite<TBufferElementData>()
    25.                 }
    26.             };
    27.          
    28.             query = GetEntityQuery(queryDesc);
    29.             RequireForUpdate(query);
    30.         }
    31.  
    32.         protected override void OnStartRunning()
    33.         {
    34.             if (!hasInitialized)
    35.             {
    36.                 Entities.WithoutBurst().ForEach((Entity entity, DotsAnimator dotsAnimator) =>
    37.                     {
    38.                         EntityManager.AddBuffer<TBufferElementData>(entity);
    39.                     })
    40.                     .Run();
    41.  
    42.                 hasInitialized = true;
    43.             }
    44.         }
    45.  
    46.         protected override JobHandle OnUpdate(JobHandle inputDependencies)
    47.         {
    48.             Entities.WithoutBurst().ForEach((DynamicBuffer<TBufferElementData> buffer, DotsAnimator dotsAnimator) =>
    49.                 {
    50.                     if (buffer.Length > 0)
    51.                     {
    52.                         for (var i = 0; i < buffer.Length; i++) SetElement(i, buffer[i], dotsAnimator);
    53.                         buffer.Clear();
    54.                     }
    55.                 })
    56.                 .Run();
    57.             return default;
    58.         }
    59.  
    60.         protected abstract void SetElement(int index, TBufferElementData elementData, DotsAnimator dotsAnimator);
    61.     }
    62. }
    I don't really understand the error itself. Also please don't mind the initialization code, it's a bit of a hack for now as I do not know exactly where I should be doing these things.
     
  2. DaseinPhaos

    DaseinPhaos

    Joined:
    Nov 20, 2017
    Posts:
    7
    Any updates on this? I came across the same exception during IL-rewrite..