From 76eeaffbb2c35453dd86f4d36a5bc0aedbc54dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 28 Nov 2022 18:44:04 +0200 Subject: [PATCH] textwrap: Don't panic on empty buffers Simply don't calculate with any duration per word for this buffer. Part-of: --- text/wrap/src/gsttextwrap/imp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index 1820a92c..9578e582 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -176,8 +176,8 @@ impl TextWrap { state.end_ts = None; } - let duration_per_word: gst::ClockTime = - duration / data.split_whitespace().count() as u64; + let num_words = data.split_whitespace().count() as u64; + let duration_per_word = (num_words != 0).then(|| duration / num_words); if state.start_ts.is_none() { state.start_ts = buffer.pts();