From 966b3ce54a6cb0eab14ec185cc036a2b7c8116f8 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Wed, 1 Jun 2022 16:55:42 +0300 Subject: [PATCH 1/3] Create a new list for sublist to fix stackoverflowerror. --- .../java/im/vector/app/features/voice/AudioWaveformView.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/voice/AudioWaveformView.kt b/vector/src/main/java/im/vector/app/features/voice/AudioWaveformView.kt index 32f30fe458..a4a4281575 100644 --- a/vector/src/main/java/im/vector/app/features/voice/AudioWaveformView.kt +++ b/vector/src/main/java/im/vector/app/features/voice/AudioWaveformView.kt @@ -156,7 +156,9 @@ class AudioWaveformView @JvmOverloads constructor( val barHeight = max(fft.value / MAX_FFT * (height - verticalPadding * 2), barMinHeight) visibleBarHeights.add(FFT(barHeight, fft.color)) if (visibleBarHeights.size > maxVisibleBarCount) { - visibleBarHeights = visibleBarHeights.subList(visibleBarHeights.size - maxVisibleBarCount, visibleBarHeights.size) + visibleBarHeights = mutableListOf().apply { + addAll(visibleBarHeights.subList(visibleBarHeights.size - maxVisibleBarCount, visibleBarHeights.size)) + } } } } From 807e89521f2ee2ae52569a43e2d190beec8860d1 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Wed, 1 Jun 2022 17:02:17 +0300 Subject: [PATCH 2/3] Changelog added. --- changelog.d/6222.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6222.bugfix diff --git a/changelog.d/6222.bugfix b/changelog.d/6222.bugfix new file mode 100644 index 0000000000..ef430ee024 --- /dev/null +++ b/changelog.d/6222.bugfix @@ -0,0 +1 @@ +Fix StackOverflowError while recording voice message From 0b9db0ee6b60de88cf9ba0e22b59c3ebf1d08972 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 6 Jun 2022 12:19:09 +0300 Subject: [PATCH 3/3] Code review fix. --- .../java/im/vector/app/features/voice/AudioWaveformView.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/voice/AudioWaveformView.kt b/vector/src/main/java/im/vector/app/features/voice/AudioWaveformView.kt index a4a4281575..944f71ef3e 100644 --- a/vector/src/main/java/im/vector/app/features/voice/AudioWaveformView.kt +++ b/vector/src/main/java/im/vector/app/features/voice/AudioWaveformView.kt @@ -151,14 +151,14 @@ class AudioWaveformView @JvmOverloads constructor( private fun handleNewFftList(fftList: List) { val maxVisibleBarCount = getMaxVisibleBarCount() + fftList.forEach { fft -> rawFftList.add(fft) val barHeight = max(fft.value / MAX_FFT * (height - verticalPadding * 2), barMinHeight) visibleBarHeights.add(FFT(barHeight, fft.color)) + if (visibleBarHeights.size > maxVisibleBarCount) { - visibleBarHeights = mutableListOf().apply { - addAll(visibleBarHeights.subList(visibleBarHeights.size - maxVisibleBarCount, visibleBarHeights.size)) - } + visibleBarHeights = visibleBarHeights.takeLast(maxVisibleBarCount).toMutableList() } } }