Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: screenshot mirroring #1017

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Sentry.Unity/ISentryUnityInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface ISentryUnityInfo
{
public bool IL2CPP { get; }
public string? Platform { get; }
public bool UvStartsAtTop { get; }
public Il2CppMethods? Il2CppMethods { get; }
}

Expand Down
16 changes: 11 additions & 5 deletions src/Sentry.Unity/ScreenshotAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry.Unity/SentryUnityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ internal string? DefaultUserId

internal List<string> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
19 changes: 19 additions & 0 deletions test/Sentry.Unity.Tests/ScriptableSentryUnityOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScriptableSentryUnityOptions>();
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; }
}
}
}
1 change: 1 addition & 0 deletions test/Sentry.Unity.iOS.Tests/SentryNativeIosTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}

Expand Down