Skip to content

Attach screenshots to iOS native crashes with runtime initialization - #2941

Merged
bitsandfoxes merged 8 commits into
mainfrom
snek/sentry-unity-ios-native-crash
Nov 12, 2026
Merged

bitsandfoxes merged 8 commits into
mainfrom
snek/sentry-unity-ios-native-crash

Conversation

@bitsandfoxes

Copy link
Copy Markdown
Contributor

With AttachScreenshot on, iOS native crashes come with a screenshot when the native SDK is initialized at runtime, the default. SentryCocoaBridgeProxy.Init passes the option to sentry-cocoa, which then takes the screenshot in its crash handler. Build-time initialization already passed it.

What sentry-cocoa attaches screenshots to, on both iOS initialization paths:

  • Native crashes: get a screenshot unless SetBeforeCaptureScreenshot or SetBeforeSendScreenshot is set. These C# callbacks can't run inside the crash handler, so a game that skips or masks screenshots through them gets no native-crash screenshot instead of an unmasked one. SentryUnityOptions.AttachNativeCrashScreenshot holds that rule for both paths.
  • Events sentry-cocoa captures itself, such as failed HTTP requests: get no screenshot. The bridge and the generated build-time options set a beforeCaptureScreenshot block that returns NO; sentry-cocoa's crash-time screenshot doesn't call it. Screenshots for C# events keep coming from the Unity SDK.
  • macOS: stays off, as sentry-cocoa has no UIKit there.

With build-time initialization, only callbacks set in the OptionsConfiguration are seen when the options are generated, as with every other build-time option.

Tests: ShouldAttachScreenshot_* in SentryNativeIosTests cover the platform, the option and both callbacks; the iOS case with the option on fails on main. NativeOptionsTests cover the generated attachScreenshot value and the beforeCaptureScreenshot block.

Not verified on a device: whether the crash-time screenshot shows the Metal-rendered game view.

🤖 Generated with Claude Code

@bitsandfoxes
bitsandfoxes marked this pull request as ready for review November 11, 2026 13:39

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3358242. Configure here.

Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
@bitsandfoxes
bitsandfoxes merged commit abcbbf7 into main Nov 12, 2026
16 of 27 checks passed
@bitsandfoxes
bitsandfoxes deleted the snek/sentry-unity-ios-native-crash branch November 12, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants