Search code examples
c#pointersunsafereflector

Cast non-pointer to pointer type in fixed expression


I'm a bit new to the unsafe side of C# so forgive me if I'm missing something obvious here.

I'm looking through some code using .NET Reflector to understand some implementation of the Oculus Rift implementation into C#, but I'm getting a bunch of errors such as this:

Error CS0030 Cannot convert type 'OVR.ViewScaleDesc' to 'OVR.ViewScaleDesc*'

Error CS0030 Cannot convert type 'OVR.LayerHeader' to 'OVR.LayerHeader*'

in the following method

public unsafe Result SubmitFrame(
        uint frameIndex, ref ViewScaleDesc viewScaleDesc, ref LayerHeader layer)
{
    fixed (ViewScaleDesc* descRef = ((ViewScaleDesc*)viewScaleDesc))
    {
        fixed (LayerHeader* headerRef = ((LayerHeader*)layer))
        {
            IntPtr layerListPtr = new IntPtr((void*)headerRef);
            return (Environment.Is64BitProcess ?
                    ovrHmd_SubmitFrame64(
                        base.NativePointer, frameIndex,
                        new IntPtr((void*)descRef), ref layerListPtr, 1) :
                        ovrHmd_SubmitFrame32(base.NativePointer, frameIndex, 
                        new IntPtr((void*)descRef),
                        ref layerListPtr, 1));// get_NativePointer()
        }
    }
}

Is the reflector giving an incorrect code here or what am I doing wrong?


Solution

  • Just drop the cast. &viewScaleDesc will work.