Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Have you experienced this? InvalidProgramException: Passing an argument of size '17432'.

Discussion in 'Entity Component System' started by davenirline, Nov 30, 2021.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    I'm getting this strange error that happens on a function call:
    InvalidProgramException: Passing an argument of size '17432'.
    Game.GenerateNewGroundSystem.OnEvent (Game.GenerateNewGround parameters) (at Assets/Game/Scripts/Ground/Systems/GenerateNewGroundSystem.cs:192)


    When I step in (debugger) into such call, it doesn't jump to the first method line. It jumps to this System code, the first constructor:
    Code (CSharp):
    1. namespace System
    2. {
    3.   /// <summary><para>The exception that is thrown when a program contains invalid Microsoft intermediate language (MSIL) or metadata. Generally this indicates a bug in the compiler that generated the program.</para></summary>
    4.   [ComVisible(true)]
    5.   [Serializable]
    6.   public sealed class InvalidProgramException : SystemException
    7.   {
    8.     /// <summary><para>Initializes a new instance of the <see cref="T:System.InvalidProgramException" /> class with default properties.</para></summary>
    9.     public InvalidProgramException()
    10.       : base(Environment.GetResourceString("Common Language Runtime detected an invalid program."))
    11.       => this.SetErrorCode(-2146233030);
    12.  
    13.     /// <summary><para>Initializes a new instance of the <see cref="T:System.InvalidProgramException" /> class with default properties.</para></summary>
    14.     public InvalidProgramException(string message)
    15.       : base(message)
    16.       => this.SetErrorCode(-2146233030);
    17.  
    18.     /// <summary><para>Initializes a new instance of the <see cref="T:System.InvalidProgramException" /> class with default properties.</para></summary>
    19.     public InvalidProgramException(string message, Exception inner)
    20.       : base(message, inner)
    21.       => this.SetErrorCode(-2146233030);
    22.  
    23.     /// <summary><para>Initializes a new instance of the <see cref="T:System.InvalidProgramException" /> class with default properties.</para></summary>
    24.     internal InvalidProgramException(SerializationInfo info, StreamingContext context)
    25.       : base(info, context)
    26.     {
    27.     }
    28.   }
    29. }
    I have no idea why this happens. Have you got clues? Will try deleting the Library folder.

    Edit: Deleting the Library folder didn't work either. What worked is reverting the refactor. What I did is I extracted a group of methods to an external struct so it can be reused. If I put this back, it works again. Strange.
     
    Last edited: Nov 30, 2021
  2. Zec_

    Zec_

    Joined:
    Feb 9, 2017
    Posts:
    148
    This sounds very much like what I experienced when having too large structs. I found the old thread about this in the DOTS NetCode forum. You can read my old post about it here:
    https://forum.unity.com/threads/net...ses-badly-generated-code.897725/#post-6309552

    What we did was to simply revamp the code so that we didn't have so large job structs. We did not realize the struct had grown so much throughout the project, and as massive structs are quite costly whenever copied we also gained a little bit of perf by revamping it as well.
     
    davenirline and cjddmut like this.
  3. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    Wow, 150 type handles! That's too big. We didn't have that big. I was trying to refactor parts of a struct into another struct so it can be reused. Then the error appeared so we reverted but I found something else.
    Code (CSharp):
    1. // Doing it like this will make the error appear
    2. RefactoredStruct refactored = new ... {
    3.     // variables assigned here
    4. };
    5.  
    6. SourceStruct source = new ... {
    7.     refactored = refactored,
    8.     ...
    9. };
    10.  
    11. // However, this works
    12. struct SourceStruct : IJobEntityBatch {\
    13.     ... // Variables needed by RefactoredStruct here
    14.  
    15.     public void Execute(...) {
    16.         // Create RefactoredStruct here
    17.         RefactoredStruct refactored = new ... {
    18.             ...
    19.         };
    20.     }
    21. }
    22.  
    23. SourceStruct source = new ... {
    24.     // Include the variables needed by RefactoredStruct here
    25. };
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Are you passing your large helper structs by value between methods or are to passing them by ref? (or not at all)
     
  5. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    They're not passed to methods at all. They're prepared in an OnUpdate() method.