From 9c63ab99f0a505b0f60079bb30cc453b4415fddc Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Fri, 1 Sep 2017 22:33:39 +0200 Subject: Fix use of unitialized variables The second in my quest to make Godot 3.x compile with -Werror on GCC7 --- editor/editor_audio_buses.cpp | 5 ++++- editor/import/resource_importer_wav.cpp | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 22 +++++++++++----------- editor/plugins/polygon_2d_editor_plugin.cpp | 2 +- editor/plugins/texture_region_editor_plugin.cpp | 7 +++++-- 5 files changed, 22 insertions(+), 16 deletions(-) (limited to 'editor') diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index b3eb3e23a9..6937f74316 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -70,11 +70,14 @@ void EditorAudioBus::_notification(int p_what) { float real_peak[2] = { -100, -100 }; bool activity_found = false; - int cc; + int cc = 0; switch (AudioServer::get_singleton()->get_speaker_mode()) { case AudioServer::SPEAKER_MODE_STEREO: cc = 1; break; case AudioServer::SPEAKER_SURROUND_51: cc = 4; break; case AudioServer::SPEAKER_SURROUND_71: cc = 5; break; + default: + ERR_PRINT("Unknown speaker_mode"); + break; } for (int i = 0; i < cc; i++) { diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index 25185149b1..e2bacd70e4 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -129,7 +129,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s int format_freq = 0; int loop_begin = 0; int loop_end = 0; - int frames; + int frames = 0; Vector data; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 601842799a..3b74601e78 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1881,7 +1881,7 @@ void CanvasItemEditor::_viewport_draw() { if (snap_show_grid) { //Draw the grid Size2 s = viewport->get_size(); - int last_cell; + int last_cell = 0; Transform2D xform = transform.affine_inverse(); Vector2 grid_offset; @@ -2257,17 +2257,17 @@ void CanvasItemEditor::_notification(int p_what) { anchors[MARGIN_RIGHT] = Object::cast_to(canvas_item)->get_anchor(MARGIN_RIGHT); anchors[MARGIN_TOP] = Object::cast_to(canvas_item)->get_anchor(MARGIN_TOP); anchors[MARGIN_BOTTOM] = Object::cast_to(canvas_item)->get_anchor(MARGIN_BOTTOM); - } - if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) { - viewport->update(); - se->prev_rect = r; - se->prev_xform = xform; - se->prev_pivot = pivot; - se->prev_anchors[MARGIN_LEFT] = anchors[MARGIN_LEFT]; - se->prev_anchors[MARGIN_RIGHT] = anchors[MARGIN_RIGHT]; - se->prev_anchors[MARGIN_TOP] = anchors[MARGIN_TOP]; - se->prev_anchors[MARGIN_BOTTOM] = anchors[MARGIN_BOTTOM]; + if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) { + viewport->update(); + se->prev_rect = r; + se->prev_xform = xform; + se->prev_pivot = pivot; + se->prev_anchors[MARGIN_LEFT] = anchors[MARGIN_LEFT]; + se->prev_anchors[MARGIN_RIGHT] = anchors[MARGIN_RIGHT]; + se->prev_anchors[MARGIN_TOP] = anchors[MARGIN_TOP]; + se->prev_anchors[MARGIN_BOTTOM] = anchors[MARGIN_BOTTOM]; + } } } diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index a3195c05d6..f7008298f0 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -659,7 +659,7 @@ void Polygon2DEditor::_uv_draw() { if (snap_show_grid) { Size2 s = uv_edit_draw->get_size(); - int last_cell; + int last_cell = 0; if (snap_step.x != 0) { for (int i = 0; i < s.width; i++) { diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 82b507bd49..38d1350b07 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -67,7 +67,7 @@ void TextureRegionEditor::_region_draw() { if (snap_mode == SNAP_GRID) { Size2 s = edit_draw->get_size(); - int last_cell; + int last_cell = 0; if (snap_step.x != 0) { if (snap_separation.x == 0) @@ -406,7 +406,7 @@ void TextureRegionEditor::_region_input(const Ref &p_input) { } else if (drag) { if (edited_margin >= 0) { - float new_margin; + float new_margin = 0; if (edited_margin == 0) new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom; else if (edited_margin == 1) @@ -415,6 +415,9 @@ void TextureRegionEditor::_region_input(const Ref &p_input) { new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom; else if (edited_margin == 3) new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom; + else + ERR_PRINT("Unexpected edited_margin"); + if (new_margin < 0) new_margin = 0; static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; -- cgit v1.2.3