Search Unity

Invoking FunctionPointer unpredictable behavior

Discussion in 'Entity Component System' started by Soaryn, Dec 23, 2019.

  1. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    328
    So, the plan was to execute a particular method based on which string I receive from a 3rd party server; however, when I got the system in place 3 things happen:
    1. Nothing malperformant happens, everything works properly
    2. The error "NotSupportedException: Delegates cannot be marshalled from native code into a domain other than their home domain" appears in the console log
    3. The editor crashes
    Understandably this is near impossible to help debug without some actual code, and while I am setting up a bug report in editor, I was wondering if anyone could shed some light as what the error was attempting to indicate. "home domain" Meaning what? :)

    As a note, this is non burstable, as I am dealing with strings (there is no way around this) so I am assigning the FunctionPointer with a helper:
    Code (CSharp):
    1. public static FunctionPointer<T> CreateFunctionPointer<T>(T t) => new FunctionPointer<T>(Marshal.GetFunctionPointerForDelegate(t));

    Update: Seemingly the issues are gone when ensuring the method being pointed at is static. May be worth it to try to see if we can override the .net error message with something more understandable in context, as in this case, I wasn't aware I was changing domains in any way.
     
    Last edited: Dec 23, 2019
  2. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    328
    Case 1207418