Skip to content

Use of invalidated reference in BestPracticesLayerXrBeginFrame #588

@jlegg0

Description

@jlegg0

BestPracticesLayerXrBeginFrame makes a reference named currentFrameState to the front item of std::deque g_framesInFlight ,

FrameState &currentFrameState = g_framesInFlight.front();

then, under some conditions, it pops the front item off of the g_framesInFlight, invalidating this reference


This reference is used after being invalidated. For example, the erased element is used as the destination of an assignment in the line after both calls to pop_front:

if (g_framesInFlight.size() > 0) currentFrameState = g_framesInFlight.front();

if (g_framesInFlight.size() > 0) currentFrameState = g_framesInFlight.front();

Perhaps these was intended to reseat the reference to refer to the new front item, but this is not possible with a C++ reference.

This occurs when skipping calling xrEndFrame for an unwanted frame, which might not be best practice, but is explicitly permitted by the OpenXR specification:

An application may call xrBeginFrame again if the prior xrEndFrame fails or if the application wishes to discard an in-progress
frame. A successful call to xrBeginFrame again with no intervening xrEndFrame call must result in the success code XR_FRAME_DISCARDED being returned from xrBeginFrame. In this case it is assumed that the xrBeginFrame refers to the next frame and the previously begun frame is forfeited by the application.

Therefore I believe the undefined behaviour is not justified in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    synced to gitlabSynchronized to OpenXR internal GitLab

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions