0

This function in the Oculus SDK gives error code 0xc0000005:

[DllImport(LibFile)]
private static extern void ovrHmd_GetRenderScaleAndOffset(ovrFovPort fov,
                                                          ovrSizei textureSize,
                                                          ovrRecti renderViewport,
                                                          [MarshalAs(UnmanagedType.LPArray, SizeConst = 2)]
                                                          [Out] out ovrVector2f[] uvScaleOffsetOut);

No other PInvoke functions throw errors, but I think this one's different because the output is an array. Actually there's one other function that returns an array, and it gives the same error:

[DllImport(LibFile)]
private static extern void ovrHmd_GetEyeTimewarpMatrices(IntPtr hmd, ovrEyeType eye, ovrPosef renderPose,
                                                         [MarshalAs(UnmanagedType.LPArray, SizeConst = 2)]
                                                         [Out] out ovrMatrix4f_Raw[] twnOut);

Here are the struct declarations:

[StructLayout(LayoutKind.Sequential)]
public struct ovrVector2f
{
    public float x, y;
}

[StructLayout(LayoutKind.Sequential)]
public struct ovrMatrix4f_Raw
{
    public float m00;
    public float m01;
    public float m02;
    public float m03;

    public float m10;
    public float m11;
    public float m12;
    public float m13;

    public float m20;
    public float m21;
    public float m22;
    public float m23;

    public float m30;
    public float m31;
    public float m32;
    public float m33;
}

Looking at the SDK source, I know at least ovrHmd_GetRenderScaleAndOffset looks pretty boring, I can't imagine the error would come from inside the SDK.

I feel like I need to specify sizes somewhere in the function signature? And I'm wondering if it's limited to output parameters, or any and all "array of struct" parameters.

4

1 回答 1

2

数组参数声明不正确。的使用out引入了虚假的额外间接级别。您需要传递一个您分配的数组,并让非托管代码填充它。像这样声明参数

private static extern void ovrHmd_GetRenderScaleAndOffset(
    ovrFovPort fov,                                       
    ovrSizei textureSize,
    ovrRecti renderViewport,
    [Out] ovrVector2f[] uvScaleOffsetOut
);

在调用函数之前分配数组:

ovrVector2f[] uvScaleOffsetOut = new ovrVector2f[2];

FWIW 如果您显示界面的非托管方面,它会有所帮助。

于 2014-09-05T06:23:43.830 回答