matzman666 / OpenVR-InputEmulator

An OpenVR driver that allows to create virtual controllers, emulate controller input, manipulate poses of existing controllers and remap buttons. A client-side library that communicates with the driver via shared-memory is also included.
GNU General Public License v3.0
710 stars 136 forks source link

getDeviceOffsets fails when remote debugging #228

Closed MasonSakai closed 11 months ago

MasonSakai commented 11 months ago

For some reason, only on my desktop (my laptop where I'm developing it doesn't have this issue), getDeviceOffsets is throwing a delayed error. It doesn't happen on it's call, but shortly after.

The weirdest thing is this isn't an indication of Input Emulator not working at all since it connects and makes the virtual trackers, but it halts on this. I've also confirmed input emulator works by itself through the UI (and of course everything works on the laptop it's being developed on)

`void UpdateRealHardwarePositions() { if (!active) return; for (vr::TrackedDeviceIndex_t unDevice = 0; unDevice < vr::k_unMaxTrackedDeviceCount; unDevice++) { if (!m_VRSystem->IsTrackedDeviceConnected(unDevice)) continue;

    vr::VRControllerState_t state;
    if (m_VRSystem->GetControllerState(unDevice, &state, sizeof(state)))
    {
        vr::TrackedDevicePose_t trackedDevicePose;
        vr::TrackedDevicePose_t trackedControllerPose;
        vr::VRControllerState_t controllerState;
        vr::HmdMatrix34_t poseMatrix;
        glm::vec3 position;
        glm::quat quaternion;
        vrinputemulator::DeviceOffsets data;
        vr::ETrackedDeviceClass trackedDeviceClass = vr::VRSystem()->GetTrackedDeviceClass(unDevice);

        switch (trackedDeviceClass) {
        case vr::ETrackedDeviceClass::TrackedDeviceClass_HMD:
            vr::VRSystem()->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseStanding, 0, &trackedDevicePose, 1);
            // print positiona data for the HMD.
            inputEmulator.getDeviceOffsets(unDevice, data);
            poseMatrix = trackedDevicePose.mDeviceToAbsoluteTracking; // This matrix contains all positional and rotational data.
            headPosReal = GetPositionGLM(trackedDevicePose.mDeviceToAbsoluteTracking) - GetPositionGLM(data.worldFromDriverTranslationOffset);
            headRotReal = GetRotationGLM(trackedDevicePose.mDeviceToAbsoluteTracking) * glm::inverse(GetRotationGLM(data.worldFromDriverRotationOffset));
            break;

        case vr::ETrackedDeviceClass::TrackedDeviceClass_Controller:
            vr::VRSystem()->GetControllerStateWithPose(vr::TrackingUniverseStanding, unDevice, &controllerState,
                sizeof(controllerState), &trackedControllerPose);
            inputEmulator.getDeviceOffsets(unDevice, data);
            poseMatrix = trackedControllerPose.mDeviceToAbsoluteTracking; // This matrix contains all positional and rotational data.
            position = GetPositionGLM(trackedControllerPose.mDeviceToAbsoluteTracking) - GetPositionGLM(data.worldFromDriverTranslationOffset);
            quaternion = GetRotationGLM(trackedControllerPose.mDeviceToAbsoluteTracking) * glm::inverse(GetRotationGLM(data.worldFromDriverRotationOffset));

            auto trackedControllerRole = vr::VRSystem()->GetControllerRoleForTrackedDeviceIndex(unDevice);

            switch (trackedControllerRole)
            {
            case vr::TrackedControllerRole_Invalid:
                // invalid
                break;
            case vr::TrackedControllerRole_LeftHand:
                leftHandPosReal = position;
                leftHandRotReal = quaternion;
                break;
            case vr::TrackedControllerRole_RightHand:
                rightHandPosReal = position;
                rightHandRotReal = quaternion;
                break;
            }

            break;
        }

    }
}

}`

an image from the debugging, strangely it's now exiting the function before aborting (but stack trace is still attributing it to getDeviceOffsets) tmp

MasonSakai commented 11 months ago

An update, the error is: "Error while enabling device offsets: Device not found" Of note, although this is the only area where it's crashing, the program is failing to enable offsets elsewhere in the program...

Though on that, I've had to, on both devices, set modal to false on all input emulator calls or I get a "vrinputemulator::vrinputemulator_notfound" exception, which may be why it's not crashing till the getDeviceOffsets call. No, it's properly making the virtual controllers...

Does there need to be a dll or something for input emulator present for it to connect, or is this just oddness with my desktop? I've taken the startup code from Playspace Mover and it's saying it's connecting successfully, so...

MasonSakai commented 11 months ago

Turns out it was because I did not have the fixed version on the desktop (despite me remembering that I did...). That fixed the issue.