Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ArgumentException:指定的结构必须是可飞行的或具有布局信息_C#_Ios_Plugins_Unity3d_Fmod - Fatal编程技术网

C# ArgumentException:指定的结构必须是可飞行的或具有布局信息

C# ArgumentException:指定的结构必须是可飞行的或具有布局信息,c#,ios,plugins,unity3d,fmod,C#,Ios,Plugins,Unity3d,Fmod,为了让这个工作顺利进行,我费了将近一个星期的劲。我已经解决了几个问题,现在当我试图将IntPtr转换为DSP_描述结构时,我陷入了这个新错误 谁能帮我照点光吗?感谢先进,你们真是太棒了 我是否需要切换到不安全模式,因为FMOD DSP_结构不可空投?我把结构的定义放在最后 **ArgumentException: The specified structure must be blittable or have layout information.** 我从对静态库函数的调用中获取IntPt

为了让这个工作顺利进行,我费了将近一个星期的劲。我已经解决了几个问题,现在当我试图将IntPtr转换为DSP_描述结构时,我陷入了这个新错误

谁能帮我照点光吗?感谢先进,你们真是太棒了

我是否需要切换到不安全模式,因为FMOD DSP_结构不可空投?我把结构的定义放在最后

**ArgumentException: The specified structure must be blittable or have layout information.**
我从对静态库函数的调用中获取IntPtr

静态库代码C++:

应用程序C:

我正在Unity3d C上编码并生成iOS项目。为iOS使用静态库*.a

public class FMOD_Listener : MonoBehaviour 
{
...
    void LoadPlugins()
    {
        //cchacon
        uint mmdsp_handle; //handler for the plugin

        FMOD.System sys = null;
        ERRCHECK(FMOD_StudioSystem.instance.System.getLowLevelSystem(out sys));
        int plugin_result = 0;

        if (Application.platform == RuntimePlatform.IPhonePlayer) {

            IntPtr FmodDescIntPtr;
            plugin_result = FMODPlugInHandler.AigooGetDSPDescription2(out FmodDescIntPtr);
            myLog = "plugin_result = " + plugin_result + " FmodDescIntPtr: " + FmodDescIntPtr; 
            Camera.main.backgroundColor = Color.blue;

            if (FmodDescIntPtr != IntPtr.Zero)
            {
                plugin_result = 838383;
                myLog = "plugin_result = " + plugin_result  + " FmodDescIntPtr: " + FmodDescIntPtr ; 
                Camera.main.backgroundColor = Color.yellow;

                DSP_DESCRIPTION FmodDesc = (DSP_DESCRIPTION)Marshal.PtrToStructure(FmodDescIntPtr, typeof(DSP_DESCRIPTION));

                plugin_result = 889911;
                myLog = "plugin_result = " + plugin_result ; 
                Camera.main.backgroundColor = Color.gray;

                ERRCHECK(sys.registerDSP(ref FmodDesc, out mmdsp_handle));

                plugin_result = 123456;
                myLog = "plugin_result = " + plugin_result ; 
                Camera.main.backgroundColor = Color.green;

            }
            else
                Console.WriteLine("FmodDescPtr is IntPtr.Zero");

        }

        if (Application.platform == RuntimePlatform.IPhonePlayer && pluginPaths.Length != 0)
        {
            FMOD.Studio.UnityUtil.LogError("DSP Plugins not currently supported on iOS, contact support@fmod.org for more information");
            return;
        }

        foreach (var name in pluginPaths)
        {
            var path = pluginPath + "/" + GetPluginFileName(name);

            FMOD.Studio.UnityUtil.Log("Loading plugin: " + path);

#if !UNITY_METRO
            if (!System.IO.File.Exists(path))
            {
                FMOD.Studio.UnityUtil.LogWarning("plugin not found: " + path);
            }
#endif

            uint handle;
            ERRCHECK(sys.loadPlugin(path, out handle));

        }
    }   

...

}
以下是结构的定义:

[StructLayout(LayoutKind.Sequential)]
public struct DSP_DESCRIPTION
{
    public uint pluginsdkversion;                          /* [w] The plugin SDK version this plugin is built for.  set to this to FMOD_PLUGIN_SDK_VERSION defined above. */
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
    public char[]                      name;               /* [w] Name of the unit to be displayed in the network. */
    public uint                        version;            /* [w] Plugin writer's version number. */
    public int                         numinputbuffers;    /* [w] Number of input buffers to process.  Use 0 for DSPs that only generate sound and 1 for effects that process incoming sound. */
    public int                         numoutputbuffers;   /* [w] Number of audio output buffers.  Only one output buffer is currently supported. */
    public DSP_CREATECALLBACK          create;             /* [w] Create callback.  This is called when DSP unit is created.  Can be null. */
    public DSP_RELEASECALLBACK         release;            /* [w] Release callback.  This is called just before the unit is freed so the user can do any cleanup needed for the unit.  Can be null. */
    public DSP_RESETCALLBACK           reset;              /* [w] Reset callback.  This is called by the user to reset any history buffers that may need resetting for a filter, when it is to be used or re-used for the first time to its initial clean state.  Use to avoid clicks or artifacts. */
    public DSP_READCALLBACK            read;               /* [w] Read callback.  Processing is done here.  Can be null. */
    public DSP_PROCESS_CALLBACK        process;            /* [w] Process callback.  Can be specified instead of the read callback if any channel format changes occur between input and output.  This also replaces shouldiprocess and should return an error if the effect is to be bypassed.  Can be null. */
    public DSP_SETPOSITIONCALLBACK     setposition;        /* [w] Setposition callback.  This is called if the unit wants to update its position info but not process data.  Can be null. */

    public int                         numparameters;      /* [w] Number of parameters used in this filter.  The user finds this with DSP::getNumParameters */
    public IntPtr                      paramdesc;          /* [w] Variable number of parameter structures. */
    public DSP_SETPARAM_FLOAT_CALLBACK setparameterfloat;  /* [w] This is called when the user calls DSP.setParameterFloat. Can be null. */
    public DSP_SETPARAM_INT_CALLBACK   setparameterint;    /* [w] This is called when the user calls DSP.setParameterInt.   Can be null. */
    public DSP_SETPARAM_BOOL_CALLBACK  setparameterbool;   /* [w] This is called when the user calls DSP.setParameterBool.  Can be null. */
    public DSP_SETPARAM_DATA_CALLBACK  setparameterdata;   /* [w] This is called when the user calls DSP.setParameterData.  Can be null. */
    public DSP_GETPARAM_FLOAT_CALLBACK getparameterfloat;  /* [w] This is called when the user calls DSP.getParameterFloat. Can be null. */
    public DSP_GETPARAM_INT_CALLBACK   getparameterint;    /* [w] This is called when the user calls DSP.getParameterInt.   Can be null. */
    public DSP_GETPARAM_BOOL_CALLBACK  getparameterbool;   /* [w] This is called when the user calls DSP.getParameterBool.  Can be null. */
    public DSP_GETPARAM_DATA_CALLBACK  getparameterdata;   /* [w] This is called when the user calls DSP.getParameterData.  Can be null. */
    public DSP_SHOULDIPROCESS_CALLBACK shouldiprocess;     /* [w] This is called before processing.  You can detect if inputs are idle and return FMOD_OK to process, or any other error code to avoid processing the effect.  Use a count down timer to allow effect tails to process before idling! */
    public IntPtr                      userdata;           /* [w] Optional. Specify 0 to ignore. This is user data to be attached to the DSP unit during creation.  Access via DSP::getUserData. */
}
这里是一些回调的定义,供参考

public delegate RESULT DSP_CREATECALLBACK           (ref DSP_STATE dsp_state);
public delegate RESULT DSP_RELEASECALLBACK          (ref DSP_STATE dsp_state);
public delegate RESULT DSP_RESETCALLBACK            (ref DSP_STATE dsp_state);
public delegate RESULT DSP_SETPOSITIONCALLBACK      (ref DSP_STATE dsp_state, uint pos);
public delegate RESULT DSP_READCALLBACK             (ref DSP_STATE dsp_state, IntPtr inbuffer, IntPtr outbuffer, uint length, int inchannels, ref int outchannels);
public delegate RESULT DSP_SHOULDIPROCESS_CALLBACK  (ref DSP_STATE dsp_state, bool inputsidle, uint length, CHANNELMASK inmask, int inchannels, SPEAKERMODE speakermode);
public delegate RESULT DSP_PROCESS_CALLBACK         (ref DSP_STATE dsp_state, uint length, ref DSP_BUFFER_ARRAY inbufferarray, ref DSP_BUFFER_ARRAY outbufferarray, bool inputsidle, DSP_PROCESS_OPERATION op);
public delegate RESULT DSP_SETPARAM_FLOAT_CALLBACK  (ref DSP_STATE dsp_state, int index, float value);
public delegate RESULT DSP_SETPARAM_INT_CALLBACK    (ref DSP_STATE dsp_state, int index, int value);
public delegate RESULT DSP_SETPARAM_BOOL_CALLBACK   (ref DSP_STATE dsp_state, int index, bool value);
public delegate RESULT DSP_SETPARAM_DATA_CALLBACK   (ref DSP_STATE dsp_state, int index, IntPtr data, uint length);
public delegate RESULT DSP_GETPARAM_FLOAT_CALLBACK  (ref DSP_STATE dsp_state, int index, ref float value, IntPtr valuestr);
public delegate RESULT DSP_GETPARAM_INT_CALLBACK    (ref DSP_STATE dsp_state, int index, ref int value, IntPtr valuestr);
public delegate RESULT DSP_GETPARAM_BOOL_CALLBACK   (ref DSP_STATE dsp_state, int index, ref bool value, IntPtr valuestr);
public delegate RESULT DSP_GETPARAM_DATA_CALLBACK   (ref DSP_STATE dsp_state, int index, ref IntPtr data, ref uint length, IntPtr valuestr);

这里的问题是委托不可飞航。我们已解决此问题:

有人了解此问题吗?经过一些调试后,我认为问题在于委托/回调。
public delegate RESULT DSP_CREATECALLBACK           (ref DSP_STATE dsp_state);
public delegate RESULT DSP_RELEASECALLBACK          (ref DSP_STATE dsp_state);
public delegate RESULT DSP_RESETCALLBACK            (ref DSP_STATE dsp_state);
public delegate RESULT DSP_SETPOSITIONCALLBACK      (ref DSP_STATE dsp_state, uint pos);
public delegate RESULT DSP_READCALLBACK             (ref DSP_STATE dsp_state, IntPtr inbuffer, IntPtr outbuffer, uint length, int inchannels, ref int outchannels);
public delegate RESULT DSP_SHOULDIPROCESS_CALLBACK  (ref DSP_STATE dsp_state, bool inputsidle, uint length, CHANNELMASK inmask, int inchannels, SPEAKERMODE speakermode);
public delegate RESULT DSP_PROCESS_CALLBACK         (ref DSP_STATE dsp_state, uint length, ref DSP_BUFFER_ARRAY inbufferarray, ref DSP_BUFFER_ARRAY outbufferarray, bool inputsidle, DSP_PROCESS_OPERATION op);
public delegate RESULT DSP_SETPARAM_FLOAT_CALLBACK  (ref DSP_STATE dsp_state, int index, float value);
public delegate RESULT DSP_SETPARAM_INT_CALLBACK    (ref DSP_STATE dsp_state, int index, int value);
public delegate RESULT DSP_SETPARAM_BOOL_CALLBACK   (ref DSP_STATE dsp_state, int index, bool value);
public delegate RESULT DSP_SETPARAM_DATA_CALLBACK   (ref DSP_STATE dsp_state, int index, IntPtr data, uint length);
public delegate RESULT DSP_GETPARAM_FLOAT_CALLBACK  (ref DSP_STATE dsp_state, int index, ref float value, IntPtr valuestr);
public delegate RESULT DSP_GETPARAM_INT_CALLBACK    (ref DSP_STATE dsp_state, int index, ref int value, IntPtr valuestr);
public delegate RESULT DSP_GETPARAM_BOOL_CALLBACK   (ref DSP_STATE dsp_state, int index, ref bool value, IntPtr valuestr);
public delegate RESULT DSP_GETPARAM_DATA_CALLBACK   (ref DSP_STATE dsp_state, int index, ref IntPtr data, ref uint length, IntPtr valuestr);