0

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?

Community
  • 1
  • 1
jsmars
  • 1,640
  • 5
  • 21
  • 33
  • Are `ViewScaleDesc` and `LayerHeader` structs or classes? – Yuval Itzchakov Aug 18 '15 at 08:50
  • I'm not sure if this is the case here, but note that there's no saying if the original code was C# in the first place - it's entirely possible it has no C# equivalent. Usually, you'd use `&` to get the pointer to a structure, but I'm not sure if that works with a `ref` argument. – Luaan Aug 18 '15 at 08:55
  • @Luaan It works with a ref argument if the type is a `struct`. Otherwise, he can't get a managed pointer to a C# class. – Yuval Itzchakov Aug 18 '15 at 08:58
  • Both ViewScaleDesc and LayerHeader are structs – jsmars Aug 18 '15 at 09:08
  • And I've tried the use of & too as thats what I could find as solutions to similar problems as such ((LayerHeader*)&layer)), but it generates this error then instead: CS0254 The right hand side of a fixed statement assignment may not be a cast expression – jsmars Aug 18 '15 at 09:10
  • 1
    Just drop the cast. Either `viewScaleDesc` or `&viewScaleDesc` will work, not sure which. – usr Aug 18 '15 at 10:02
  • Can't believe I didn't try that. &viewScaleDesc was the correct way to do it, thanks alot! You should submit this as an answer and I'll mark it as such. – jsmars Aug 18 '15 at 11:07

1 Answers1

2

Just drop the cast. &viewScaleDesc will work.

usr
  • 168,620
  • 35
  • 240
  • 369