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

Error on PS4 with il2cpp #233

Closed
d11ahirst opened this issue Jun 16, 2021 · 12 comments
Closed

Error on PS4 with il2cpp #233

d11ahirst opened this issue Jun 16, 2021 · 12 comments
Labels
Bug Something isn't working

Comments

@d11ahirst
Copy link

Environment

Plugin 0.2.0

How do you use Sentry?
Onpremise

Which SDK and version?
Net 2.0.0

Steps to Reproduce

Initialised sentry plugin on PS4 Console on boot

Expected Result

No Errors

What you thought would happen.

No Errors

Actual Result

Debug: Logging enabled with ConsoleDiagnosticLogger and min level: Debug
ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime.
Parameter name: value
at Sentry.Internal.ProcessInfo..ctor (Sentry.SentryOptions options, System.Func`1[TResult] findPreciseStartupTime) [0x00000] in <00000000000000000000000000000000>:0
at Sentry.SentrySdk.InitHub (Sentry.SentryOptions options) [0x00000] in <00000000000000000000000000000000>:0
at Sentry.SentrySdk.Init (Sentry.SentryOptions options) [0x00000] in <00000000000000000000000000000000>:0
at Bootstrap.Start () [0x00000] in <00000000000000000000000000000000>:0

(Filename: currently not available on il2cpp Line: -1)

What actually happened. Maybe a screenshot/recording? Maybe some logs?

@bruno-garcia
Copy link
Member

bruno-garcia commented Jun 16, 2021

@d11ahirst what version of the SDK are you using?

I believe this was resolved on version 0.0.8 already: https://github.com/getsentry/sentry-unity/blob/main/CHANGELOG.md#fixes-8

ProcessInfo is not supported on IL2CPP so we turned that feature off for Unity.

Sorry I see you wrote the version.

What do you mean by SDK version "Net 2.0.0"?

@bruno-garcia bruno-garcia added Bug Something isn't working PlayStation4 labels Jun 16, 2021
@d11ahirst
Copy link
Author

Sorry for the confusion, we are using Unity 2019.3 with il2cpp on the PS4

@semuserable
Copy link
Contributor

Very interesting... My assumption.

Does it mean that DateTimeOffset.UtcNow gets something like 01/01/0001 (ie DateTimeOffset.MinValue) on PS4? Sentry .NET "substracts" time in ProcessInfo during hub creation.

var now = DateTimeOffset.UtcNow;
StartupTime = now;
try
{
    BootTime = now.AddTicks(-Stopwatch.GetTimestamp()
                            / (Stopwatch.Frequency
                               / TimeSpan.TicksPerSecond));
}

If we try to substract something from DateTimeOffset.MinValue, we recieve the mentioned exception.

@bruno-garcia
Copy link
Member

We rely on DateTimeOffset.UtcNow to add a timestamp to the Sentry Event and crumbs and other parts of the SDK so it would be very surprising if that returned DateTimeOffset.MinValue.

I think it's more likely this returns it min value:
https://github.com/getsentry/sentry-dotnet/blob/f84c23b9683c8d90880d613701fd9359528061bb/src/Sentry/Internal/ProcessInfo.cs#L93-L94

But that's the part that shouldn't be called on Unity because DetectStartupTime is not Best:

// IL2CPP doesn't support Process.GetCurrentProcess().StartupTime
DetectStartupTime = StartupTimeDetectionMode.Fast;

I'll make sure that failing to instantiate ProcessInfo won't bubble out of the SDK so "worst case" we don't have that timestamp but things work fine.

@bruno-garcia
Copy link
Member

@d11ahirst could you please try initializing the SDK programatically and set options.DetectStartupTime = StartupTimeDetectionMode.None ?

Without the line number we can only guess and I just want to make sure my patch will work.

@bruno-garcia
Copy link
Member

Opened this to address the issue: getsentry/sentry-dotnet#1062

@d11ahirst
Copy link
Author

@bruno-garcia

I tried options.DetectStartupTime = StartupTimeDetectionMode.None and it seems to be getting past it.

However sentry is now returning this

Sentry: Error
An error occurred when capturing the event UnityEngine.UnityException: GetOperatingSystem can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
  at (wrapper managed-to-native) UnityEngine.EditorSystemInfo.GetOperatingSystem()
  at UnityEngine.EditorSystemInfo.get_operatingSystem () [0x00001] in <8ee633f6dccc459bbde4324d82f7c465>:0 
  at UnityEngine.SystemInfoShimBase.get_operatingSystem () [0x00000] in <8ee633f6dccc459bbde4324d82f7c465>:0 
  at UnityEngine.SystemInfo.get_operatingSystem () [0x00005] in <8ee633f6dccc459bbde4324d82f7c465>:0 
  at Sentry.Unity.UnityEventProcessor.Process (Sentry.SentryEvent event) [0x00035] in D:\a\sentry-unity\sentry-unity\src\Sentry.Unity\UnityEventProcessor.cs:37 
  at Sentry.SentryClient.DoSendEvent (Sentry.SentryEvent event, Sentry.Scope scope) [0x001cb] in <c15f2d7635c44e498f5ab4870f374e64>:0 
  at Sentry.SentryClient.CaptureEvent (Sentry.SentryEvent event, Sentry.Scope scope) [0x0001f] in <c15f2d7635c44e498f5ab4870f374e64>:0 .

UnityEngine.Debug:LogError(Object)
Sentry.Unity.UnityLogger:Log(SentryLevel, String, Exception, Object[]) (at D:/a/sentry-unity/sentry-unity/src/Sentry.Unity/UnityLogger.cs:42)
Sentry.Extensibility.DiagnosticLoggerExtensions:LogIfEnabled(IDiagnosticLogger, SentryLevel, String, Exception, SentryId, Exception)
Sentry.Extensibility.DiagnosticLoggerExtensions:LogError(IDiagnosticLogger, String, Exception, SentryId)
Sentry.SentryClient:CaptureEvent(SentryEvent, Scope)
Sentry.Internal.Hub:CaptureEvent(SentryEvent, Scope)
Sentry.SentryClientExtensions:CaptureException(ISentryClient, Exception)
Sentry.Integrations.TaskUnobservedTaskExceptionIntegration:Handle(Object, UnobservedTaskExceptionEventArgs)
Sentry.Internal.AppDomainAdapter:OnUnobservedTaskException(Object, UnobservedTaskExceptionEventArgs)
System.Threading.Tasks.TaskExceptionHolder:Finalize()

@bruno-garcia
Copy link
Member

bruno-garcia commented Jun 18, 2021

@d11ahirst That message means our UnobservedTaskException integration captured an exception but it failed to capture because it tried to enrich the event with GetOperatingSystem which can't be called outside of the main thread. We'll fix this but in the mean time could you please try a work around:

Work around for that is to call options.DisableTaskUnobservedTaskExceptionCapture()

But good point, this also means that a call to Capture outside of the main thread it can fail with the same error. We need to call such APIs only on the main thread (likely when initializing).

The unity logger we subscribe to fires on the main thread though so at least the unity errors should work normally.

@bruno-garcia
Copy link
Member

bruno-garcia commented Jun 18, 2021

@d11ahirst if you'd like, we can chat on Discord (we have a #unity channel there), Sentry's Discord: https://discord.gg/sentry
I'd also be glad to hope on a call with you and see this through if you're interested feel free to write me: bruno at sentry dot io

@semuserable
Copy link
Contributor

semuserable commented Jun 18, 2021

Should we cache the values from SystemInfo during startup? As far as I can tell, Unity doesn't cache it on C# level, most (all?) properties call to extern.

Example:

[FreeFunction("systeminfo::GetOperatingSystem")]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string GetOperatingSystem();

@bruno-garcia
Copy link
Member

Yes but at the same time if we're eager calling all of these APIs we'll slow down the startup of the game so lets explore other avenues where we can call these APIs asynchronously but running on the main thread. Any event captured before these APIs are called and cached would just not include that data (or if the capture is called from the UI thread we could block while we run the APIs and cache the data for the first time).

@bruno-garcia
Copy link
Member

Issues described here were resolved on 0.3.0. Please let us know if it works out for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants