Skip to content

Commit f2ea2f0

Browse files
committed
fix(replay): Skip MediaMuxer stop when no samples were written
MediaMuxer.stop() throws IllegalStateException when the muxer was started but no sample was ever written to its track. SimpleMp4FrameMuxer.release() only guarded against the never-started case, so a started-but-empty muxer made release() throw. Because release() runs from SimpleVideoEncoder's finally block, that throw propagates out to createVideoOf, which treats release() as safe cleanup; the encoder is left dangling and the orphan video file is never deleted. Only call stop() when at least one sample was written; muxer.release() on a started-but-not-stopped muxer is safe.
1 parent 45b652d commit f2ea2f0

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

sentry-android-replay/src/main/java/io/sentry/android/replay/video/SimpleMp4FrameMuxer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ internal class SimpleMp4FrameMuxer(path: String, fps: Float) : SimpleFrameMuxer
6767
}
6868

6969
override fun release() {
70-
// stop() throws if the muxer was never started (e.g. no frame was ever muxed), so we guard it
71-
// to ensure release() is always reached and the underlying resources are freed
72-
if (started) {
70+
// stop() throws unless the muxer was started AND at least one sample was written, so we guard it
71+
// to ensure muxer.release() is always reached and the underlying resources are freed
72+
if (started && videoFrames > 0) {
7373
muxer.stop()
7474
}
7575
muxer.release()

0 commit comments

Comments
 (0)