From ed15636fd7616e9171b862e3bd42aebeac027b17 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Tue, 29 Nov 2022 10:56:48 +0100 Subject: [PATCH 1/4] fix(screenshots): Don't capture zero size screenshots --- CHANGELOG.md | 6 ++++++ Sources/Sentry/SentryScreenshot.m | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f6ca4b08d..031a4ad684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Don't capture zero size screenshots + ## 7.31.2 ### Fixes diff --git a/Sources/Sentry/SentryScreenshot.m b/Sources/Sentry/SentryScreenshot.m index a3eba3e120..f48c82d010 100644 --- a/Sources/Sentry/SentryScreenshot.m +++ b/Sources/Sentry/SentryScreenshot.m @@ -47,7 +47,9 @@ - (void)saveScreenShots:(NSString *)path if ([window drawViewHierarchyInRect:window.bounds afterScreenUpdates:false]) { UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); - [result addObject:UIImagePNGRepresentation(img)]; + if (img.size.width > 0 && img.size.height > 0) { + [result addObject:UIImagePNGRepresentation(img)]; + } } UIGraphicsEndImageContext(); From 7d9c5950361833125c290fed5bd26a5f3252a4e9 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Tue, 29 Nov 2022 11:32:07 +0100 Subject: [PATCH 2/4] Update changelog with pr id --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 031a4ad684..cec3bc0d42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- Don't capture zero size screenshots +- Don't capture zero size screenshots ([#2459](https://github.com/getsentry/sentry-cocoa/pull/2459)) ## 7.31.2 From d8f9d5fe89aa6c08f789d7e7f5f87319d410d1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Wold=C5=99ich?= <31292499+krystofwoldrich@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:20:58 +0100 Subject: [PATCH 3/4] Update Sources/Sentry/SentryScreenshot.m Co-authored-by: Dhiogo Brustolin --- Sources/Sentry/SentryScreenshot.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentryScreenshot.m b/Sources/Sentry/SentryScreenshot.m index f48c82d010..7b378f708b 100644 --- a/Sources/Sentry/SentryScreenshot.m +++ b/Sources/Sentry/SentryScreenshot.m @@ -47,8 +47,11 @@ - (void)saveScreenShots:(NSString *)path if ([window drawViewHierarchyInRect:window.bounds afterScreenUpdates:false]) { UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); - if (img.size.width > 0 && img.size.height > 0) { - [result addObject:UIImagePNGRepresentation(img)]; + if (img.size.width > 0 || img.size.height > 0) { + NSData* bytes = UIImagePNGRepresentation(img); + if (bytes && bytes.length > 0) { + [result addObject:bytes]; + } } } From 645d46937a82d9b441107f984ec8d58df2413f41 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 29 Nov 2022 14:03:20 +0000 Subject: [PATCH 4/4] Format code --- Sources/Sentry/SentryScreenshot.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentryScreenshot.m b/Sources/Sentry/SentryScreenshot.m index 7b378f708b..9fe1ee45ab 100644 --- a/Sources/Sentry/SentryScreenshot.m +++ b/Sources/Sentry/SentryScreenshot.m @@ -48,9 +48,9 @@ - (void)saveScreenShots:(NSString *)path if ([window drawViewHierarchyInRect:window.bounds afterScreenUpdates:false]) { UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); if (img.size.width > 0 || img.size.height > 0) { - NSData* bytes = UIImagePNGRepresentation(img); + NSData *bytes = UIImagePNGRepresentation(img); if (bytes && bytes.length > 0) { - [result addObject:bytes]; + [result addObject:bytes]; } } }