diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs index 3f42071d1..3be55c5ef 100644 --- a/package-dev/Runtime/SentryInitialization.cs +++ b/package-dev/Runtime/SentryInitialization.cs @@ -138,6 +138,15 @@ public string Platform ; } + public bool UvStartsAtTop + { +#if UNITY_EDITOR + get => false; +#else + get => UNITY_UV_STARTS_AT_TOP == 1; +#endif + } + public Il2CppMethods Il2CppMethods => _il2CppMethods; private Il2CppMethods _il2CppMethods diff --git a/src/Sentry.Unity/ISentryUnityInfo.cs b/src/Sentry.Unity/ISentryUnityInfo.cs index dabc7da6f..3989dd50b 100644 --- a/src/Sentry.Unity/ISentryUnityInfo.cs +++ b/src/Sentry.Unity/ISentryUnityInfo.cs @@ -6,6 +6,7 @@ public interface ISentryUnityInfo { public bool IL2CPP { get; } public string? Platform { get; } + public bool UvStartsAtTop { get; } public Il2CppMethods? Il2CppMethods { get; } } diff --git a/src/Sentry.Unity/ScreenshotAttachment.cs b/src/Sentry.Unity/ScreenshotAttachment.cs index e8a55adef..07354646c 100644 --- a/src/Sentry.Unity/ScreenshotAttachment.cs +++ b/src/Sentry.Unity/ScreenshotAttachment.cs @@ -72,16 +72,22 @@ private byte[] CaptureScreenshot() var renderTextureFull = RenderTexture.GetTemporary(Screen.width, Screen.height); ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTextureFull); var renderTextureResized = RenderTexture.GetTemporary(width, height); - // On all (currently supported) platforms except Android, the image is mirrored horizontally & vertically. - // So we must mirror it back. - if (ApplicationAdapter.Instance.Platform is (RuntimePlatform.Android or RuntimePlatform.LinuxPlayer)) + + // The image may be mirrored on some platforms - mirror it back. + // See https://docs.unity3d.com/2019.4/Documentation/Manual/SL-PlatformDifferences.html for more info. + if (_options.UnityInfo?.UvStartsAtTop is false) { - Graphics.Blit(renderTextureFull, renderTextureResized); + _options.DiagnosticLogger?.Log(SentryLevel.Debug, + "UvStartsAtTop is false"); + Graphics.Blit(renderTextureFull, renderTextureResized, new Vector2(1, -1), new Vector2(0, 1)); } else { - Graphics.Blit(renderTextureFull, renderTextureResized, new Vector2(1, -1), new Vector2(0, 1)); + _options.DiagnosticLogger?.Log(SentryLevel.Debug, + "UvStartsAtTop is true"); + Graphics.Blit(renderTextureFull, renderTextureResized); } + RenderTexture.ReleaseTemporary(renderTextureFull); // Remember the previous render target and change it to our target texture. var previousRenderTexture = RenderTexture.active; diff --git a/src/Sentry.Unity/SentryUnityOptions.cs b/src/Sentry.Unity/SentryUnityOptions.cs index c7cd6cb13..f6c089db9 100644 --- a/src/Sentry.Unity/SentryUnityOptions.cs +++ b/src/Sentry.Unity/SentryUnityOptions.cs @@ -145,11 +145,13 @@ internal string? DefaultUserId internal List SdkIntegrationNames { get; set; } = new(); + internal ISentryUnityInfo? UnityInfo; + public SentryUnityOptions() : this(false, null, ApplicationAdapter.Instance) { } internal SentryUnityOptions(bool isBuilding, ISentryUnityInfo? unityInfo, IApplication application) : this(SentryMonoBehaviour.Instance, application, isBuilding) - { } + { UnityInfo = unityInfo; } internal SentryUnityOptions(SentryMonoBehaviour behaviour, IApplication application, bool isBuilding) { diff --git a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs index cb41d567b..d103b055d 100644 --- a/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs +++ b/test/Sentry.Unity.Android.Tests/SentryNativeAndroidTests.cs @@ -97,6 +97,7 @@ public class TestSentryUnityInfo : ISentryUnityInfo { public bool IL2CPP { get; set; } public string? Platform { get; } + public bool UvStartsAtTop { get; } public Il2CppMethods? Il2CppMethods { get; } } } diff --git a/test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs b/test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs index 7bb93d56e..3fd5a7d2d 100644 --- a/test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs +++ b/test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs @@ -170,5 +170,24 @@ private static string GetTestOptionsFilePath() Assert.NotNull(assemblyFolderPath); return Path.Combine(assemblyFolderPath!, TestSentryOptionsFileName); } + + [Test] + public void ToSentryUnityOptions_Sets_UnityInfo() + { + var scriptableOptions = ScriptableObject.CreateInstance(); + var unityInfo = new TestSentryUnityInfo(); + var options = scriptableOptions.ToSentryUnityOptions(false, unityInfo); + + Assert.IsNotNull(options.UnityInfo); + Assert.AreEqual(options.UnityInfo, unityInfo); + } + + private class TestSentryUnityInfo : ISentryUnityInfo + { + public bool IL2CPP { get; set; } + public string? Platform { get; } + public bool UvStartsAtTop { get; } + public Il2CppMethods? Il2CppMethods { get; } + } } } diff --git a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs index c4809f11b..2088edeed 100644 --- a/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs +++ b/test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs @@ -8,6 +8,7 @@ public class TestSentryUnityInfo : ISentryUnityInfo { public bool IL2CPP { get; set; } public string? Platform { get; } + public bool UvStartsAtTop { get; } public Il2CppMethods? Il2CppMethods { get; } }