From 301731c7e6f3c74d72d18781faa34c402781ce94 Mon Sep 17 00:00:00 2001 From: RedworkDE <10944644+RedworkDE@users.noreply.github.com> Date: Tue, 30 May 2023 16:49:58 +0200 Subject: [PATCH] Fix crash in AudioStream preview --- editor/import/audio_stream_import_settings.cpp | 9 +++++---- editor/plugins/audio_stream_editor_plugin.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/editor/import/audio_stream_import_settings.cpp b/editor/import/audio_stream_import_settings.cpp index c32218bbfc8..abf56c7ef8f 100644 --- a/editor/import/audio_stream_import_settings.cpp +++ b/editor/import/audio_stream_import_settings.cpp @@ -78,6 +78,7 @@ void AudioStreamImportSettings::_notification(int p_what) { void AudioStreamImportSettings::_draw_preview() { Rect2 rect = _preview->get_rect(); Size2 rect_size = rect.size; + int width = rect_size.width; Ref preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); float preview_offset = zoom_bar->get_value(); @@ -86,12 +87,12 @@ void AudioStreamImportSettings::_draw_preview() { Ref beat_font = get_theme_font(SNAME("main"), SNAME("EditorFonts")); int main_size = get_theme_font_size(SNAME("main_size"), SNAME("EditorFonts")); Vector points; - points.resize((int)rect_size.width * 2); + points.resize(width * 2); Color color_active = get_theme_color(SNAME("contrast_color_2"), SNAME("Editor")); Color color_inactive = color_active; color_inactive.a *= 0.5; Vector colors; - colors.resize((int)rect_size.width); + colors.resize(width); float inactive_from = 1e20; float beat_size = 0; @@ -108,7 +109,7 @@ void AudioStreamImportSettings::_draw_preview() { } } - for (int i = 0; i < rect_size.width; i++) { + for (int i = 0; i < width; i++) { float ofs = preview_offset + i * preview_len / rect_size.width; float ofs_n = preview_offset + (i + 1) * preview_len / rect_size.width; float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5; @@ -139,7 +140,7 @@ void AudioStreamImportSettings::_draw_preview() { int bar_beats = stream->get_bar_beats(); int last_text_end_x = 0; - for (int i = 0; i < rect_size.width; i++) { + for (int i = 0; i < width; i++) { float ofs = preview_offset + i * preview_len / rect_size.width; int beat = int(ofs / beat_size); if (beat != prev_beat) { diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp index e8fc4e76bb7..e01849ff268 100644 --- a/editor/plugins/audio_stream_editor_plugin.cpp +++ b/editor/plugins/audio_stream_editor_plugin.cpp @@ -75,7 +75,8 @@ void AudioStreamEditor::_notification(int p_what) { void AudioStreamEditor::_draw_preview() { Size2 size = get_size(); - if ((int)size.width <= 0) { + int width = size.width; + if (width <= 0) { return; // No points to draw. } @@ -85,9 +86,9 @@ void AudioStreamEditor::_draw_preview() { float preview_len = preview->get_length(); Vector points; - points.resize((int)size.width * 2); + points.resize(width * 2); - for (int i = 0; i < size.width; i++) { + for (int i = 0; i < width; i++) { float ofs = i * preview_len / size.width; float ofs_n = (i + 1) * preview_len / size.width; float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5;