Skip to content

Commit 8c2f79b

Browse files
authored
fix(replay): Fix crash when root view has no window or is too small (#4805)
* fix(replay): Fix crash when root view has no window or is too small * Changelog * move the null check under if(added) * revert * revert
1 parent b9ea522 commit 8c2f79b

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- Avoid StrictMode warnings ([#4724](https://github.com/getsentry/sentry-java/pull/4724))
2020
- Use logger from options for JVM profiler ([#4771](https://github.com/getsentry/sentry-java/pull/4771))
2121
- Session Replay: Avoid deadlock when pausing replay if no connection ([#4788](https://github.com/getsentry/sentry-java/pull/4788))
22+
- Session Replay: Fix capturing roots with no windows ([#4805](https://github.com/getsentry/sentry-java/pull/4805))
23+
- Session Replay: Fix `java.lang.IllegalArgumentException: width and height must be > 0` ([#4805](https://github.com/getsentry/sentry-java/pull/4805))
2224

2325
### Miscellaneous
2426

sentry-android-replay/src/main/java/io/sentry/android/replay/ScreenshotRecorder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public data class ScreenshotRecorderConfig(
289289
private fun Int.adjustToBlockSize(): Int {
290290
val remainder = this % 16
291291
return if (remainder <= 8) {
292-
this - remainder
292+
maxOf(16, this - remainder)
293293
} else {
294294
this + (16 - remainder)
295295
}

sentry-android-replay/src/main/java/io/sentry/android/replay/WindowRecorder.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ internal class WindowRecorder(
110110
override fun onRootViewsChanged(root: View, added: Boolean) {
111111
rootViewsLock.acquire().use {
112112
if (added) {
113+
if (root.phoneWindow == null) {
114+
options.logger.log(WARNING, "Root view does not have a phone window, skipping.")
115+
return
116+
}
117+
113118
rootViews.add(WeakReference(root))
114119
capturer?.recorder?.bind(root)
115120
determineWindowSize(root)

0 commit comments

Comments
 (0)