diff --git a/CHANGELOG.md b/CHANGELOG.md index c6c409b721c..4bc6bb509a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This version adds a dependency on Swift. - Increase `SentryCrashMAX_STRINGBUFFERSIZE` to reduce the instances where we're dropping a crash due to size limit (#2465) - `SentryAppStateManager` correctly unsubscribes from `NSNotificationCenter` when closing the SDK (#2460) - The SDK no longer reports an OOM when a crash happens after closing the SDK (#2468) +- Don't capture zero size screenshots ([#2459](https://github.com/getsentry/sentry-cocoa/pull/2459)) - Use the preexisting app release version format for profiles (#2470) ### Breaking Changes diff --git a/Sources/Sentry/SentryScreenshot.m b/Sources/Sentry/SentryScreenshot.m index a3eba3e120b..9fe1ee45ab2 100644 --- a/Sources/Sentry/SentryScreenshot.m +++ b/Sources/Sentry/SentryScreenshot.m @@ -47,7 +47,12 @@ - (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) { + NSData *bytes = UIImagePNGRepresentation(img); + if (bytes && bytes.length > 0) { + [result addObject:bytes]; + } + } } UIGraphicsEndImageContext(); diff --git a/Tests/SentryTests/SentryScreenShotTests.swift b/Tests/SentryTests/SentryScreenShotTests.swift index e8dc6725486..351d72697bb 100644 --- a/Tests/SentryTests/SentryScreenShotTests.swift +++ b/Tests/SentryTests/SentryScreenShotTests.swift @@ -80,7 +80,18 @@ class SentryScreenShotTests: XCTestCase { XCTAssertEqual(image?.size.width, 10) XCTAssertEqual(image?.size.height, 10) + } + + func test_ZeroSizeScreenShot_GetsDiscarded() { + let testWindow = TestWindow(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + fixture.uiApplication.windows = [testWindow] + + guard let data = self.fixture.sut.appScreenshots() else { + XCTFail("Could not make window screenshot") + return + } + XCTAssertEqual(0, data.count, "No screenshot should be taken, cause the image has zero size.") } class TestSentryUIApplication: SentryUIApplication {