fix: Screenshot Capture#2240
Conversation
|
|
||
| public void CaptureScreenshotForEvent(SentryUnityOptions options, SentryId eventId) | ||
| { | ||
| StartCoroutine(CaptureScreenshot(options, eventId)); |
There was a problem hiding this comment.
This method returns before the coroutine starts/ends, right? how do we know the screenshot will be taken before the event is created?
There was a problem hiding this comment.
The ScreenshotProcessor forwards the call to the SentryMonoBehaviour that starts the coroutine for the current EndOfFrame.
276efc3 to
11548fe
Compare
|
CI is unhappy |
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
|
@sentry review |
| $BuildDir = $(GetNewProjectBuildPath) | ||
| $ApkFileName = "test.apk" | ||
| $ProcessName = "com.DefaultCompany.$(GetNewProjectName)" | ||
| $ProcessName = "io.sentry.unity.integrationtest" |
There was a problem hiding this comment.
With Unity 6 integration tests seem to fail to have their proper identifier set, causing the build to fail. We're setting this now explicitly in the Builder.cs and making use of the hardcoded name here.
| internal virtual byte[] CaptureScreenshot(SentryUnityOptions options) | ||
| => SentryScreenshot.Capture(options); | ||
|
|
||
| internal virtual void CaptureAttachment(SentryId eventId, SentryAttachment attachment) | ||
| => (Sentry.SentrySdk.CurrentHub as Hub)?.CaptureAttachment(eventId, attachment); | ||
|
|
||
| internal virtual YieldInstruction WaitForEndOfFrame() | ||
| => new WaitForEndOfFrame(); |
There was a problem hiding this comment.
I'm making these virtual so I can create a TestScreenshotEventProcessor that overwrites these for testing purposes.
|
|
||
| // This is a workaround for build issues with Unity 2022.3. and newer. | ||
| // https://discussions.unity.com/t/gradle-build-issues-for-android-api-sdk-35-in-unity-2022-3lts/1502187/10 | ||
| #if UNITY_2022_3_OR_NEWER | ||
| Debug.Log("Builder: Setting Android target API level to 33"); | ||
| PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevel33; | ||
| #endif | ||
|
|
There was a problem hiding this comment.
Workaround that is no longer needed.
Fixes #2224, #1827 🎉
Relies on the .NET SDK getsentry/sentry-dotnet#4357
Context
The SDK has to wait for
EndOfFramebefore capturing a screenshot as the behaviour is unreliable otherwise. See Unity docs.Implementation
The
ScreenshotProcessoruses theSentryMonoBehaviourto start a coroutine that waits forEnd of Frameto capture the screenshot. The screenshot gets sent as an envelop with a single attachment as envelope item.