Resuming application after removing headset

I’m integrating OpenXR into my app, currently testing with an Oculus Rift S running with the Meta Horizons app.

As I understand it, I need to end and delete a session when the user removes the headset, and create a new session when they put it back on. When I remove the headset, xrPollEvent retrieves a STATE_CHANGED event, with the state set to XR_SESSION_STATE_STOPPING. In response to this, I call XrEndSession and XrDestroySession.

When I put the headset back on, I am in the default “home” area for the Meta app. No more events are received by xrPollEvent(). If I point at the app in the Meta menu and click the trigger, nothing happens. I have confirmed that XrEndSession and XrDeleteSession are both returning XR_SUCCESS.

How is my application supposed to detect the app is resuming, so it can create a new session?

void XRSystem::Update()
{
    XrEventDataBuffer eventData{ XR_TYPE_EVENT_DATA_BUFFER };
    while (xrPollEvent(m_instance, &eventData) == XR_SUCCESS)
    {
        switch (eventData.type)
        {
        case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED:
            auto sessionStateChanged = (XrEventDataSessionStateChanged*)&eventData;
            current_session_state = sessionStateChanged->state;
            switch (sessionStateChanged->state)
            {
            case XR_SESSION_STATE_STOPPING:
                if (m_session != XR_NULL_HANDLE)
                {
                    XrResult r = xrEndSession(m_session);
                    if (r == XR_SUCCESS)
                    {
                        r = xrDestroySession(m_session);
                        m_session = XR_NULL_HANDLE;
                    }
                }
                return;
                break;
            case XR_SESSION_STATE_SYNCHRONIZED:
            case XR_SESSION_STATE_VISIBLE:
            case XR_SESSION_STATE_READY:
            case XR_SESSION_STATE_FOCUSED:
                if (m_session == XR_NULL_HANDLE)
                {
                    CreateSession(m_graphicsBinding.hDC, m_graphicsBinding.hGLRC);
                }
                break;
            }
            break;
        }
        eventData = { XR_TYPE_EVENT_DATA_BUFFER };
    }
    if (m_session == XR_NULL_HANDLE) return;

Ah, you don’t destroy the session, you just call xrBeginSession again on the same session.