3

私は公式の Kinect SDK 1.5 の例の 1 つを使用しており、Kinect が切断されていることを検出するチェックを追加する方法を見つけようとしています。現在、アプリはフリーズするだけなので、これを防ぐ方法が必要です。

これは、SDK の例からのメイン メッセージ ループです。

// Main message loop
while (WM_QUIT != msg.message)
{
    hEvents[0] = m_hNextDepthFrameEvent;

    // Check to see if we have either a message (by passing in QS_ALLINPUT)
    // Or a Kinect event (hEvents)
    // Update() will check for Kinect events individually, in case more than one are signalled
    DWORD dwEvent = MsgWaitForMultipleObjects(eventCount, hEvents, FALSE, INFINITE, QS_ALLINPUT);

    // Check if this is an event we're waiting on and not a timeout or message
    if (WAIT_OBJECT_0 == dwEvent)
    {
        Update();
    }

    // does not work.
    bool bla = m_pNuiSensor->NuiStatus();
    if (NULL == m_pNuiSensor)
    {
            cout << 1 << endl;
    }

    if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
    {
        // If a dialog message will be taken care of by the dialog proc
        if ((hWndApp != NULL) && IsDialogMessageW(hWndApp, &msg))
        {
            continue;
        }

        TranslateMessage(&msg);
        DispatchMessageW(&msg);
    }
}

return static_cast<int>(msg.wParam);

次のビットを追加しました。

    // does not work, bla will always be the same value.
    bool bla = m_pNuiSensor->NuiStatus();
    if (NULL == m_pNuiSensor)
    {
            cout << 1 << endl;
    }

NuiStatusおそらく切断を検出する方法になると思っていたので。残念ながら、うまくいきません。かどうかのチェックも同様m_pNuiSensorですNULL

では、実行中のアプリで切断を検出する方法は何ですか?

EDIT1:使用する必要がありNuiSetDeviceStatusCallbackますか?

4

2 に答える 2

2

ドキュメントでは、NuiStatus は bool ではなく HRESULT を返すと記載されているため、そうすべきではありません

HRESULT bla = m_pNuiSensor->NuiStatus();
if (bla == E_NUI_NOTCONNECTED)
{
        cout << 1 << endl;
}

代わりは?

于 2012-10-02T14:45:03.803 に答える
0

次の解決策が機能します。

    // check if m_pNuiSensor is initialized.
    if (NULL != m_pNuiSensor)
    {
        // get current status & check if not ok.
        HRESULT current_status = m_pNuiSensor->NuiStatus();
        if (current_status != S_OK )
        {
            SetStatusMessage(L"Lost connection to Kinect!");
        }
    }
于 2012-10-02T14:43:26.967 に答える