summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAle Camara <services@alecamara.com>2022-11-13 20:23:18 +0000
committerAle Camara <services@alecamara.com>2022-11-14 13:21:48 +0000
commit9a666a9275ede73d24cd86e37ac2e324af65eca9 (patch)
tree71b2e8b2f83c0caa748db242dc2c3ab91c52534a
parentb05e1e7d6982c1a0ebbba2e1da60bf05fd2a009a (diff)
Fix editor crash on audio preview
- Crash was due to getting -1 values when clamping [0, -1]. - This was happening due to 'max' being zero. - If 'max' is zero we should return zero, as it can never be any other value.
-rw-r--r--editor/audio_stream_preview.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp
index b9e52ad7ad..f99025ad06 100644
--- a/editor/audio_stream_preview.cpp
+++ b/editor/audio_stream_preview.cpp
@@ -42,6 +42,10 @@ float AudioStreamPreview::get_max(float p_time, float p_time_next) const {
}
int max = preview.size() / 2;
+ if (max == 0) {
+ return 0;
+ }
+
int time_from = p_time / length * max;
int time_to = p_time_next / length * max;
time_from = CLAMP(time_from, 0, max - 1);
@@ -69,6 +73,10 @@ float AudioStreamPreview::get_min(float p_time, float p_time_next) const {
}
int max = preview.size() / 2;
+ if (max == 0) {
+ return 0;
+ }
+
int time_from = p_time / length * max;
int time_to = p_time_next / length * max;
time_from = CLAMP(time_from, 0, max - 1);