Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetFrameTimings not works in c#? #1001

Closed
Zaetc opened this issue Jan 17, 2019 · 5 comments
Closed

GetFrameTimings not works in c#? #1001

Zaetc opened this issue Jan 17, 2019 · 5 comments

Comments

@Zaetc
Copy link

Zaetc commented Jan 17, 2019

GetFrameTiming works fine. (it ok, but it is not optimal way if you need get many Compositor_FrameTiming)
But GetFrameTimings brings to crashes (System.AccessViolationException).
May be I'm doing something wrong?
Here is code:

 private Compositor_FrameTiming[] GetFrames2()
        {
            Compositor_FrameTiming[] framestimesBuffer = new Compositor_FrameTiming[40];
            framestimesBuffer[0].m_nSize = Convert.ToUInt32(System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming)));
            uint ft = OpenVR.Compositor.GetFrameTimings(ref framestimesBuffer[0], 40);
            if (ft != 40)
            {
                /// do sometning
            }
            return framestimesBuffer;
        }
@BOLL7708
Copy link

I noticed this as well, so I just went with grabbing the frame timing very often instead, as I'm doing live frame timing analysis. It's a while since I looked at this, I think loading timings worked if I only asked for 1-2 frames, which made it kind of pointless, if I actually remember it correctly.

@aleiby
Copy link
Contributor

aleiby commented Jan 29, 2019

That function is missing the proper mark up to have it export properly in the C# bindings. Here's what you can do to change this locally until we get a new version of the SDK updated with the fix.

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
internal delegate uint _GetFrameTimings([In, Out] Compositor_FrameTiming[] pTiming, uint nFrames);
[MarshalAs(UnmanagedType.FunctionPtr)]
internal _GetFrameTimings GetFrameTimings;

public uint GetFrameTimings(Compositor_FrameTiming [] pTiming)
{
	uint result = FnTable.GetFrameTimings(pTiming,(uint) pTiming.Length);
	return result;
}

Then you just call like:

var timing = new Compositor_FrameTiming[8];
timing[0].m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
vr.compositor.GetFrameTimings(timing);

@aleiby aleiby closed this as completed Jan 30, 2019
@aleiby
Copy link
Contributor

aleiby commented Jan 30, 2019

Should be fixed in the next SDK update. Thanks!

@BOLL7708
Copy link

Thanks for replying here @aleiby, this got me to post about something else in the C# header I've been thinking about for a long time now 😅 I have a few other things regarding the header as well that I'll try to post eventually, need to do some more testing first though.

jeremyselan pushed a commit that referenced this issue Jan 30, 2019
General:
 * Added new, more specific error messages for many compositor startup failures.
 * Fix for IVRCompositor.GetFrameTimings C# binding (#1001)

Event and Overlay changes:
 * Scroll events have been split into two types. The first, VREvent_ScrollDiscrete, is meant for applications that are tuned to accept primarily detented mousewheel events, which replaces the previous VREvent_Scroll event. The second, VREvent_ScrollSmooth, is for applications that are tuned for more touchscreen-like, analog scrolling.
 * VROverlayFlags have been updated to allow overlays to indicate their preferred scroll event type. The VROverlayFlags_SendVRDiscreteScrollEvents flag renames the VROverlayFlags_SendVRScrollEvents flag, and the overlay will receive VREvent_ScrollDiscrete events when this flag is set. The VROverlayFlags_SendVRSmoothScrollEvents flag is added, and the overlay's owning application will receive VREvent_ScrollSmooth events when this flag is set.
 * VREvent_Input_BindingsUpdated is sent when a user has updated controller bindings using the system input binding UI.

IVRIOBuffer:
 * Adds ability for writers to detect if an IOBuffer has readers (IVRIOBuffer::HasReaders), to avoid potentially expensive writing work

[git-p4: depot-paths = "//vr/steamvr/sdk_release/": change = 4924548]
jeremyselan pushed a commit that referenced this issue Jan 30, 2019
General:
 * Added new, more specific error messages for many compositor startup failures.
 * Fix for IVRCompositor.GetFrameTimings C# binding (#1001)
 * Added VRNotifications and VRIOBuffer C# accessors.

Event and Overlay changes:
 * Scroll events have been split into two types. The first, VREvent_ScrollDiscrete, is meant for applications that are tuned to accept primarily detented mousewheel events, which replaces the previous VREvent_Scroll event. The second, VREvent_ScrollSmooth, is for applications that are tuned for more touchscreen-like, analog scrolling.
 * VROverlayFlags have been updated to allow overlays to indicate their preferred scroll event type. The VROverlayFlags_SendVRDiscreteScrollEvents flag renames the VROverlayFlags_SendVRScrollEvents flag, and the overlay will receive VREvent_ScrollDiscrete events when this flag is set. The VROverlayFlags_SendVRSmoothScrollEvents flag is added, and the overlay's owning application will receive VREvent_ScrollSmooth events when this flag is set.
 * VREvent_Input_BindingsUpdated is sent when a user has updated controller bindings using the system input binding UI.

IVRIOBuffer:
 * Adds ability for writers to detect if an IOBuffer has readers (IVRIOBuffer::HasReaders), to avoid potentially expensive writing work

[git-p4: depot-paths = "//vr/steamvr/sdk_release/": change = 4926575]
@BOLL7708
Copy link

@aleiby I finally got to updating my implementation, I'm providing an array Compositor_FrameTiming[] and the result count I get back matches the array size so it would appear to be working, but then all objects in the array are still empty (just instantiated with default primitives). Am I missing something here? 🤔 Meanwhile I can successfully get data from GetFrameTiming().

Could it be that the array reference is replaced while not passed as reference? I tried adding the key word but no difference on my end, so not sure. Did make a fiddle to check my sanity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants