Various uninitialised variable fixes
authorCraig Robbins <kde.psych@gmail.com>
Tue, 7 Oct 2014 07:01:07 +0000 (17:01 +1000)
committerKahrl <kahrl@gmx.net>
Sun, 19 Oct 2014 13:33:08 +0000 (15:33 +0200)
sky.cpp: m_bgcolor.getAlpha() was being used before initialised

mesh related: m_highlight_mesh_color was being used uninitialised

src/client.cpp
src/content_mapblock.cpp
src/mapblock_mesh.cpp
src/sky.cpp
src/sky.h

index 0bc2e66a52efed56a35d4bf06bcf9e2e74c0ab69..7e74cf36bbd1341069b633a1bfbe9bcec9a93dbf 100644 (file)
@@ -250,6 +250,7 @@ Client::Client(
        m_inventory_updated(false),
        m_inventory_from_server(NULL),
        m_inventory_from_server_age(0.0),
+       m_show_hud(true),
        m_animation_time(0),
        m_crack_level(-1),
        m_crack_pos(0,0,0),
index 53b9874d4971dde18b2b27dcdfaa7eb457d410f8..996db421b35e030cce74b432788a4f695acaacac 100644 (file)
@@ -188,10 +188,10 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 
        // Create selection mesh
        v3s16 p = data->m_highlighted_pos_relative;
-       if (data->m_show_hud & 
-                       (p.X >= 0) & (p.X < MAP_BLOCKSIZE) &
-                       (p.Y >= 0) & (p.Y < MAP_BLOCKSIZE) &
-                       (p.Z >= 0) & (p.Z < MAP_BLOCKSIZE)) {
+       if (data->m_show_hud &&
+                       (p.X >= 0) && (p.X < MAP_BLOCKSIZE) &&
+                       (p.Y >= 0) && (p.Y < MAP_BLOCKSIZE) &&
+                       (p.Z >= 0) && (p.Z < MAP_BLOCKSIZE)) {
 
                MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
                if(n.getContent() != CONTENT_AIR) {
@@ -215,7 +215,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                                        l = l1;
                        }
                        video::SColor c = MapBlock_LightColor(255, l, 0);
-                       data->m_highlight_mesh_color = c;       
+                       data->m_highlight_mesh_color = c;
                        std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
                        TileSpec h_tile;                        
                        h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;
index a7fafa68341fd8b549ddff135eef8177f82fb240..2459cf0d7e5963818ce1dea5b61c970a253e0f70 100644 (file)
@@ -48,6 +48,8 @@ MeshMakeData::MeshMakeData(IGameDef *gamedef):
        m_crack_pos_relative(-1337, -1337, -1337),
        m_highlighted_pos_relative(-1337, -1337, -1337),
        m_smooth_lighting(false),
+       m_show_hud(false),
+       m_highlight_mesh_color(255, 255, 255, 255),
        m_gamedef(gamedef)
 {}
 
@@ -330,7 +332,7 @@ static void finalColorBlend(video::SColor& result,
 
        // Emphase blue a bit in darker places
        // Each entry of this array represents a range of 8 blue levels
-       static u8 emphase_blue_when_dark[32] = {
+       static const u8 emphase_blue_when_dark[32] = {
                1, 4, 6, 6, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        };
@@ -338,7 +340,7 @@ static void finalColorBlend(video::SColor& result,
        b = irr::core::clamp (b, 0, 255);
 
        // Artificial light is yellow-ish
-       static u8 emphase_yellow_when_artificial[16] = {
+       static const u8 emphase_yellow_when_artificial[16] = {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 10, 15, 15, 15
        };
        rg += emphase_yellow_when_artificial[night/16];
@@ -1086,7 +1088,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
 
        mapblock_mesh_generate_special(data, collector);
 
-       m_highlight_mesh_color = data->m_highlight_mesh_color; 
+       m_highlight_mesh_color = data->m_highlight_mesh_color;
 
        /*
                Convert MeshCollector to SMesh
index 17d8d46ce4dc788acdb6bc63b064ceadff25f5b8..b5706f4e3e9afa65abe24bfed495a9af60a3c645 100644 (file)
@@ -573,6 +573,20 @@ void Sky::update(float time_of_day, float time_brightness,
                m_clouds_visible = false;
        }
 
+       video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
+       m_bgcolor = video::SColor(
+               255,
+               bgcolor_bright.getRed() * m_brightness,
+               bgcolor_bright.getGreen() * m_brightness,
+               bgcolor_bright.getBlue() * m_brightness);
+
+       video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
+       m_skycolor = video::SColor(
+               255,
+               skycolor_bright.getRed() * m_brightness,
+               skycolor_bright.getGreen() * m_brightness,
+               skycolor_bright.getBlue() * m_brightness);
+
        // Horizon coloring based on sun and moon direction during sunset and sunrise
        video::SColor pointcolor = video::SColor(255, 255, 255, m_bgcolor.getAlpha());
        if (m_directional_colored_fog) {
@@ -606,25 +620,7 @@ void Sky::update(float time_of_day, float time_brightness,
                        // calculate the blend color
                        pointcolor = m_mix_scolor(pointcolor_moon, pointcolor_sun, pointcolor_blend);
                }
-       }
-
-       video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
-       m_bgcolor = video::SColor(
-               255,
-               bgcolor_bright.getRed() * m_brightness,
-               bgcolor_bright.getGreen() * m_brightness,
-               bgcolor_bright.getBlue() * m_brightness);
-       if (m_directional_colored_fog) {
                m_bgcolor = m_mix_scolor(m_bgcolor, pointcolor, m_horizon_blend() * 0.5);
-       }
-
-       video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
-       m_skycolor = video::SColor(
-               255,
-               skycolor_bright.getRed() * m_brightness,
-               skycolor_bright.getGreen() * m_brightness,
-               skycolor_bright.getBlue() * m_brightness);
-       if (m_directional_colored_fog) {
                m_skycolor = m_mix_scolor(m_skycolor, pointcolor, m_horizon_blend() * 0.25);
        }
 
index d7dabedb80640315520de95c81ffa92d1ac1dc5d..4af6be0246bbfaeb5f1d3b847d398915e47a8948 100644 (file)
--- a/src/sky.h
+++ b/src/sky.h
@@ -79,7 +79,8 @@ private:
        {
                if (!m_sunlight_seen)
                        return 0;
-               float x; m_time_of_day >= 0.5 ? x = (1 - m_time_of_day) * 2 : x = m_time_of_day * 2;
+               float x = m_time_of_day >= 0.5 ? (1 - m_time_of_day) * 2 : m_time_of_day * 2;
+
                if (x <= 0.3)
                        return 0;
                if (x <= 0.4) // when the sun and moon are aligned