Skip to content

Crash trying to capture screenshot when ensure() is triggered soon after starting PIE (Viewport is null) #1329

@KostasVsNT

Description

@KostasVsNT

Environment

Sentry SaaS (sentry.io)

Which version of the SDK?

1.8.0

Which version of Unreal?

5.7.2

Steps to Reproduce

It's complicated. I reproed it twice in a row, and then it stopped... One of our artists could repro it consistently.

We have some custom engine code that happens to trigger an ensure in the RHIThread, under certain conditions. The details probably aren't important. All we have to do is enter PIE (Play In Editor), and then the ensure triggers pretty much straight away.

What happens then is that we get into SentryScreenshotUtils::CaptureScreenshot(), and GameViewportClient->Viewport is null. GEngine->GameViewport is actually set, so the existing checks pass, and then it crashes at line 30.

Most likely some race condition. I assume that UGameViewportClient::SetViewportFrame is about to be called in another thread, but hasn't yet.

Side note: A bit scary that there is no thread synchronisation at all here, apparently. Even simple pointer assignment isn't always guaranteed to be atomic, I believe.

Strangely, when I try it in the debugger, I can enter PIE and start playing, and UGameViewportClient::SetViewportFrame is only called afterwards, when I exit PIE. Not sure what to make of this.

Adding a simple null check in SentryScreenshotUtils::CaptureScreenshot(), beneath the existing checks would make all this safe, I think. Even if I can't reliably prove it. Like the comment says, screenshot generation is on a best-effort basis, so no screenshot is better than a crash. With that in mind, maybe the exact details for triggering a repro don't matter. As long as UGameViewportClient can exist while SetViewportFrame hasn't been called yet, this crash will be possible.

What do you think?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugsomething isn't working as it shouldErrorsissues relates to the error reporting productUnreal Engineplatform label
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions