Skip to content

Instantly share code, notes, and snippets.

@jeremyselan
Created October 24, 2016 23:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyselan/d567b427298d46e1f9882333b6af5a94 to your computer and use it in GitHub Desktop.
Save jeremyselan/d567b427298d46e1f9882333b6af5a94 to your computer and use it in GitHub Desktop.
OpenVR GetStringTrackedDeviceProperty Wrapper
std::string GetStringTrackedDeviceProperty( vr::IVRSystem * pSystem, vr::TrackedDeviceIndex_t unDeviceIndex, vr::ETrackedDeviceProperty prop, vr::ETrackedPropertyError *pError )
{
vr::ETrackedPropertyError err = TrackedProp_Success;
std::string sRetVal;
char buf[32];
uint32_t unPropLen = pSystem->GetStringTrackedDeviceProperty( unDeviceIndex, prop, buf, sizeof( buf ), &err );
if ( err == vr::TrackedProp_Success )
{
sRetVal = buf;
}
else if ( err == vr::TrackedProp_BufferTooSmall )
{
char *pchBuffer = new char[unPropLen];
unPropLen = pSystem->GetStringTrackedDeviceProperty( unDeviceIndex, prop, pchBuffer, unPropLen, &err );
if ( err == vr::TrackedProp_Success )
{
sRetVal = pchBuffer;
}
delete[] pchBuffer;
}
if ( pError )
{
*pError = err;
}
return sRetVal;
}
@elect86
Copy link

elect86 commented Feb 7, 2017

Nice wrapper, I was about to write one similar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment