In Visual Studio, After passing parameters by pointer or reference of visual studio function, the access parameter value in the function is null

  c++, function, openvr, visual-studio

This is the main code where error happened:

void VRInputRemapping::DigitalInputConfig() {
bool orginput = this->curVRConfig->GetorgDigitalInput();
uint32_t deviceId = this->curVRConfig->GetcurDeviceId();
uint32_t buttonId = this->curVRConfig->GetcurButtonId();

printf("Digital orginput: %d      device:%d    butonid:%dn", orginput, deviceId, buttonId);
vrinputemulator::DigitalInputRemapping* m_currentRemapping =new vrinputemulator::DigitalInputRemapping(true);
vrinputemulator::DigitalBinding* m_currentBinding = new vrinputemulator::DigitalBinding;
if (orginput == false) {
    m_currentBinding->type = vrinputemulator::DigitalBindingType::Disabled;
    memset(&m_currentBinding->data, 0, sizeof(m_currentBinding->data));
    m_currentBinding->data.openvr.buttonId = buttonId;
    m_currentBinding->toggleEnabled = false;
    m_currentBinding->toggleDelay = 0;
    m_currentBinding->autoTriggerEnabled = false;
    m_currentBinding->autoTriggerFrequency = 1;
    m_currentRemapping->binding = *m_currentBinding;
}
else if (orginput == true) {
    m_currentBinding->type = vrinputemulator::DigitalBindingType::NoRemapping;
    memset(&m_currentBinding->data, 0, sizeof(m_currentBinding->data));
    m_currentBinding->data.openvr.buttonId = buttonId;
    m_currentBinding->toggleEnabled = false;
    m_currentBinding->toggleDelay = 0;
    m_currentBinding->autoTriggerEnabled = false;
    m_currentBinding->autoTriggerFrequency = 1;
    m_currentRemapping->binding = *m_currentBinding;
}

    printf(" void VRInputRemapping::DigitalInputConfig()  m_currentRemapping->binding.type:%d      device:%d    buttonId:%d  remapping.data.openvr.buttonId%dn", m_currentRemapping->binding.type, deviceId, buttonId, m_currentRemapping->binding.data.openvr.buttonId);

//<——————–Here is the function call————————————–>

this->inputEmulator->setDigitalInputRemapping(deviceId, buttonId, m_currentRemapping);

//<——————–Here is the function call————————————–>

    printf(" void VRInputRemapping::DigitalInputConfig()  m_currentRemapping->binding.type:%d      device:%d    buttonId:%d  remapping.data.openvr.buttonId%dn", m_currentRemapping->binding.type, deviceId, buttonId, m_currentRemapping->binding.data.openvr.buttonId);

delete m_currentBinding;
delete m_currentRemapping;
Sleep(1);

}

This is the Function:

void VRInputEmulator::setDigitalInputRemapping(uint32_t deviceId, uint32_t buttonId, DigitalInputRemapping* remapping, bool modal) {
printf("VRInputEmulator::setDigitalInputRemapping   Digital orginput: %d      device:%d    butonid:%d    remapping->binding.data.openvr.buttonId%dn", remapping->binding.type, deviceId, buttonId, remapping->binding.data.openvr.buttonId);
if (_ipcServerQueue) {
    ipc::Request message(ipc::RequestType::InputRemapping_SetDigitalRemapping);
    memset(&message.msg, 0, sizeof(message.msg));
    message.msg.ir_SetDigitalRemapping.clientId = m_clientId;
    message.msg.ir_SetDigitalRemapping.messageId = 0;
    message.msg.ir_SetDigitalRemapping.controllerId = deviceId;
    message.msg.ir_SetDigitalRemapping.buttonId = buttonId;
    message.msg.ir_SetDigitalRemapping.remapData = *remapping;
    if (modal) {
        uint32_t messageId = _ipcRandomDist(_ipcRandomDevice);
        message.msg.ir_SetDigitalRemapping.messageId = messageId;
        std::promise<ipc::Reply> respPromise;
        auto respFuture = respPromise.get_future();
        {
            std::lock_guard<std::recursive_mutex> lock(_mutex);
            _ipcPromiseMap.insert({ messageId, std::move(respPromise) });
        }
        _ipcServerQueue->send(&message, sizeof(ipc::Request), 0);
        auto resp = respFuture.get();
        {
            std::lock_guard<std::recursive_mutex> lock(_mutex);
            _ipcPromiseMap.erase(messageId);
        }
        std::stringstream ss;
        ss << "Error while setting digital input remapping: ";
        if (resp.status == ipc::ReplyStatus::InvalidId) {
            ss << "Invalid device id";
            throw vrinputemulator_invalidid(ss.str(), (int)resp.status);
        } else if (resp.status == ipc::ReplyStatus::NotFound) {
            ss << "Device not found";
            throw vrinputemulator_notfound(ss.str(), (int)resp.status);
        } else if (resp.status != ipc::ReplyStatus::Ok) {
            ss << "Error code " << (int)resp.status;
            throw vrinputemulator_exception(ss.str(), (int)resp.status);
        }
    } else {
        _ipcServerQueue->send(&message, sizeof(ipc::Request), 0);
    }
} else {
    throw vrinputemulator_connectionerror("No active connection.");
}

}

You can See the Printf I had use before and after the function call, also used in the head of the dunction,This is the output:

    void VRInputRemapping::DigitalInputConfig()  m_currentRemapping->binding.type:0      device:1    buttonId:32  remapping.data.openvr.buttonId:  32
VRInputEmulator::setDigitalInputRemapping   Digital orginput: 0      device:1    butonid:32    remapping->binding.data.openvr.buttonId:  0
 void VRInputRemapping::DigitalInputConfig()  m_currentRemapping->binding.type 0      device:1    buttonId:32  remapping.data.openvr.buttonId:  32

The output in the consloe

Source: Windows Questions C++

LEAVE A COMMENT