You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Record at end of frame i.e. a coroutine yield return new WaitForEndOfFrame() and not in the middle of rendering
ScreenCapture.CaptureScreenshotAsTexture() returns a Texture2D that can be encoded to .png, .jpg, .tga byte[]
Also:
Native screenshot would be better, ensures always receiving a screenshot when the exception is threaded or from a java/objective-c error (so long as it didn't crash)
Need to resize it before compressing to jpg, make the max height and compress amount a setting
This is my current implementation but most of the time I'd love to have screenshots for native exceptions, they are harder to diagnose.
public class ScreenshotAttachment : IAttachmentContent
{
public Stream GetStream()
{
if (!UnityThread.IsRunningOnUnityThread)
return new MemoryStream();
float ratio = (float)Screen.width / (float)Screen.height;
int targetHeight = Mathf.Min(Screen.height, 360);
int targetWidth = Mathf.RoundToInt((float)targetHeight * ratio);
RenderTexture screenshot = RenderTexture.GetTemporary(Screen.width, Screen.height);
ScreenCapture.CaptureScreenshotIntoRenderTexture(screenshot);
// Create a render texture to render into
RenderTexture screenshotResize = RenderTexture.GetTemporary(targetWidth, targetHeight, 0);
Graphics.Blit(screenshot, screenshotResize);
RenderTexture.ReleaseTemporary(screenshot);
RenderTexture previousActiveRT = RenderTexture.active;
RenderTexture.active = screenshotResize;
// Create a texture & read data from the active RenderTexture
Texture2D result = new Texture2D(targetWidth, targetHeight) { name = "Screenshot" };
result.ReadPixels(new Rect(0, 0, targetWidth, targetHeight), 0, 0);
result.Apply();
// Reset to initial state
RenderTexture.active = previousActiveRT;
RenderTexture.ReleaseTemporary(screenshotResize);
var stream = new MemoryStream(result.EncodeToJPG(80));
result.SafeDestroy();
return stream;
}
}
If you allowed attachment streams to be async we could implement screenshots fairly easily ourselves. Or even just give us a callback 1 frame before you actually call GetStream
Record at end of frame i.e. a coroutine yield return new WaitForEndOfFrame() and not in the middle of rendering
ScreenCapture.CaptureScreenshotAsTexture() returns a Texture2D that can be encoded to .png, .jpg, .tga byte[]
Also:
Native screenshot would be better, ensures always receiving a screenshot when the exception is threaded or from a java/objective-c error (so long as it didn't crash)
Need to resize it before compressing to jpg, make the max height and compress amount a setting
This is my current implementation but most of the time I'd love to have screenshots for native exceptions, they are harder to diagnose.
public class ScreenshotAttachment : IAttachmentContent
{
public Stream GetStream()
{
if (!UnityThread.IsRunningOnUnityThread)
return new MemoryStream();
float ratio = (float)Screen.width / (float)Screen.height;
int targetHeight = Mathf.Min(Screen.height, 360);
int targetWidth = Mathf.RoundToInt((float)targetHeight * ratio);
RenderTexture screenshot = RenderTexture.GetTemporary(Screen.width, Screen.height);
ScreenCapture.CaptureScreenshotIntoRenderTexture(screenshot);
// Create a render texture to render into
RenderTexture screenshotResize = RenderTexture.GetTemporary(targetWidth, targetHeight, 0);
Graphics.Blit(screenshot, screenshotResize);
RenderTexture.ReleaseTemporary(screenshot);
RenderTexture previousActiveRT = RenderTexture.active;
RenderTexture.active = screenshotResize;
// Create a texture & read data from the active RenderTexture
Texture2D result = new Texture2D(targetWidth, targetHeight) { name = "Screenshot" };
result.ReadPixels(new Rect(0, 0, targetWidth, targetHeight), 0, 0);
result.Apply();
// Reset to initial state
RenderTexture.active = previousActiveRT;
RenderTexture.ReleaseTemporary(screenshotResize);
var stream = new MemoryStream(result.EncodeToJPG(80));
result.SafeDestroy();
return stream;
}
}
If you allowed attachment streams to be async we could implement screenshots fairly easily ourselves. Or even just give us a callback 1 frame before you actually call GetStream
If BeforeSend would be async we could also set attachments in the context without problems no?
To be honest I never expected Sentry would not have a feature like this... Unity Diagnostics doesn't have 1/10 part of the features you own but does have the screenshot... I dont mean to criticize is just a screenshot of the game just when the exception happened is extremely useful and might save you a lot of time finding where a problem is.
I hope you guys consider giving some priority to this or a temporary workaround.
Thanks a lot!
@pistoleta Here's an updated version that works some of the time. You just add it to your Configure(SentryUnityOptions options) method.
publicclassScreenshotAttachment:IAttachmentContent,UnityEngine.ILogHandler{privateILogHandlerhandler;privateTexture2Dscreenshot;publicScreenshotAttachment(){handler=Debug.unityLogger.logHandler;Debug.unityLogger.logHandler=this;}privateasyncTaskCapture(){Debug.Log("Capturing screenshot");awaitnewWaitForEndOfFrame();floatratio=(float)Screen.width/(float)Screen.height;inttargetHeight=Mathf.Min(Screen.height,360);inttargetWidth=Mathf.RoundToInt((float)targetHeight*ratio);RenderTexturescreenshotRt=RenderTexture.GetTemporary(Screen.width,Screen.height);ScreenCapture.CaptureScreenshotIntoRenderTexture(screenshotRt);// Create a render texture to render intoRenderTexturescreenshotResize=RenderTexture.GetTemporary(targetWidth,targetHeight,0);
##if UNITY_IOS||UNITY_EDITORGraphics.Blit(screenshotRt,screenshotResize,newVector2(1,-1),newVector2(0,1));
##else
Graphics.Blit(screenshotRt,screenshotResize);
##endif
RenderTexture.ReleaseTemporary(screenshotRt);RenderTexturepreviousActiveRT=RenderTexture.active;RenderTexture.active=screenshotResize;// Create a texture & read data from the active RenderTexturescreenshot=newTexture2D(targetWidth,targetHeight){name="Screenshot"};screenshot.ReadPixels(newRect(0,0,targetWidth,targetHeight),0,0);screenshot.Apply();}publicStreamGetStream(){if(screenshot==null){UnityEngine.Debug.Log("Returning empty stream due to missing screenshot texture2d");returnnewMemoryStream();}varstream=newMemoryStream(screenshot.EncodeToJPG(80));screenshot.SafeDestroy();UnityEngine.Debug.Log("captured screenshot attachment");returnstream;}publicvoidLogFormat(LogTypelogType,UnityEngine.Objectcontext,stringformat,paramsobject[]args){handler.LogFormat(logType,context,format,args);}publicasyncvoidLogException(Exceptionexception,UnityEngine.Objectcontext){awaitCapture();handler.LogException(exception,context);}}
I downloaded last release and used the example for sending screenshot but the screenshot seems to be captured upwards.... any hint where the problem might be? I used the exact same code provided in the example.
I downloaded last release and used the example for sending screenshot but the screenshot seems to be captured upwards.... any hint where the problem might be? I used the exact same code provided in the example.
iOS, btw i had to comment: result.SafeDestroy();
since Texture2D doesn't have that method implemented. What's this line supposed to do, release it from memory?
Do you mean the example code, not the new functionality implemented by the latest version? That example is old and doesn't do proper mirroring (necessary for most platforms)
Sorry to see you run into problems.
Could you open up a new issue detailing what happened, where (platform, Unity-version), and what you had to do to get there/fix it? The Attach Screenshot feature is supposed to work out of the box and you definitely should not have to comment anything to make it work.
sorry but I dont see any image attachment, neither from iOS reports or if I send one from unity editor... I enabled from the settings In tools->sentry and also I the SentryOptionsCOnfiguration ScriptableObject.
Activity
bitsandfoxes commentedon Aug 23, 2021
Gotchas to keep in mind:
bruno-garcia commentedon Dec 14, 2021
Strategy on Xamarin changed:
https://github.com/getsentry/sentry-xamarin/blob/main/Src/Sentry.Xamarin/Internals/Device/Screenshot/ScreenshotAttachment.cs
https://github.com/getsentry/sentry-xamarin/blob/main/Src/Sentry.Xamarin/Internals/Device/Screenshot/ScreenshotAttachmentContent.cs
Would be nice to have a Sample so users can see the usage when they import the package.
Unmerged spec PR: getsentry/develop#422
oddgames-david commentedon Dec 22, 2021
Also:
This is my current implementation but most of the time I'd love to have screenshots for native exceptions, they are harder to diagnose.
bitsandfoxes commentedon Dec 23, 2021
The resizing of the screenshot is a good catch. Thanks for sharing!
The native screenshot is a good idea and something that's planned to be added.
oddgames-david commentedon Mar 16, 2022
If you allowed attachment streams to be async we could implement screenshots fairly easily ourselves. Or even just give us a callback 1 frame before you actually call GetStream
pistoleta commentedon Mar 28, 2022
How do you attach this to the event?
pistoleta commentedon Mar 28, 2022
If BeforeSend would be async we could also set attachments in the context without problems no?
pistoleta commentedon Mar 28, 2022
To be honest I never expected Sentry would not have a feature like this... Unity Diagnostics doesn't have 1/10 part of the features you own but does have the screenshot... I dont mean to criticize is just a screenshot of the game just when the exception happened is extremely useful and might save you a lot of time finding where a problem is.
I hope you guys consider giving some priority to this or a temporary workaround.
Thanks a lot!
bruno-garcia commentedon Mar 29, 2022
This is a priority to us. We're adding support for screenshots on iOS and Android, and there's a thumbnail in Sentry's issue detail page.
The spec for SDK development is here: https://develop.sentry.dev/sdk/features/#screenshots and we plan on adding this to Unity too
oddgames-david commentedon Mar 30, 2022
@pistoleta Here's an updated version that works some of the time. You just add it to your Configure(SentryUnityOptions options) method.
edit by @vaind: fix the codeblock
8 remaining items
oddgames-david commentedon Apr 4, 2022
@vaind I'd watch out for black screenshots when not using
yield new WaitForEndOfFrame();pistoleta commentedon Apr 27, 2022
I downloaded last release and used the example for sending screenshot but the screenshot seems to be captured upwards.... any hint where the problem might be? I used the exact same code provided in the example.
bitsandfoxes commentedon Apr 28, 2022
Which platform did you target?
pistoleta commentedon Apr 28, 2022
iOS, btw i had to comment:
result.SafeDestroy();since Texture2D doesn't have that method implemented. What's this line supposed to do, release it from memory?
vaind commentedon Apr 28, 2022
Do you mean the example code, not the new functionality implemented by the latest version? That example is old and doesn't do proper mirroring (necessary for most platforms)
bitsandfoxes commentedon Apr 28, 2022
Sorry to see you run into problems.
Could you open up a new issue detailing what happened, where (platform, Unity-version), and what you had to do to get there/fix it? The
Attach Screenshotfeature is supposed to work out of the box and you definitely should not have to comment anything to make it work.bitsandfoxes commentedon Apr 28, 2022
If you're updating the Sentry package you also have to update the samples coming with it.
vaind commentedon Apr 28, 2022
Also, there's no
result.SafeDestroy();anywhere in this repository as far as I can tell - what example are you actually referring to?pistoleta commentedon Apr 28, 2022
wrong script 🤦 , seems I already had a ScreenShotAttachement that tried to make work some time ago. Apologies
bitsandfoxes commentedon Apr 29, 2022
No worries! Happy to see it worked out for you regardless!
pistoleta commentedon Apr 29, 2022
sorry but I dont see any way to attach screenshot in the 0.15.0 at least nothing new in the examples
vaind commentedon Apr 29, 2022
you can enable it in the settings in the Unity UI (Tools->Sentry)
pistoleta commentedon Apr 29, 2022
awesome, sorry I didnt see it in the changelog
pistoleta commentedon Apr 30, 2022
sorry but I dont see any image attachment, neither from iOS reports or if I send one from unity editor... I enabled from the settings In tools->sentry and also I the SentryOptionsCOnfiguration ScriptableObject.