Skip to content

Commit 076c5ee

Browse files
Zeno-kahrl
authored andcommittedOct 19, 2014
Various uninitialised variable fixes
sky.cpp: m_bgcolor.getAlpha() was being used before initialised mesh related: m_highlight_mesh_color was being used uninitialised
1 parent fe8ef1b commit 076c5ee

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed
 

‎src/client.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ Client::Client(
250250
m_inventory_updated(false),
251251
m_inventory_from_server(NULL),
252252
m_inventory_from_server_age(0.0),
253+
m_show_hud(true),
253254
m_animation_time(0),
254255
m_crack_level(-1),
255256
m_crack_pos(0,0,0),

‎src/content_mapblock.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
188188

189189
// Create selection mesh
190190
v3s16 p = data->m_highlighted_pos_relative;
191-
if (data->m_show_hud &
192-
(p.X >= 0) & (p.X < MAP_BLOCKSIZE) &
193-
(p.Y >= 0) & (p.Y < MAP_BLOCKSIZE) &
194-
(p.Z >= 0) & (p.Z < MAP_BLOCKSIZE)) {
191+
if (data->m_show_hud &&
192+
(p.X >= 0) && (p.X < MAP_BLOCKSIZE) &&
193+
(p.Y >= 0) && (p.Y < MAP_BLOCKSIZE) &&
194+
(p.Z >= 0) && (p.Z < MAP_BLOCKSIZE)) {
195195

196196
MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
197197
if(n.getContent() != CONTENT_AIR) {
@@ -215,7 +215,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
215215
l = l1;
216216
}
217217
video::SColor c = MapBlock_LightColor(255, l, 0);
218-
data->m_highlight_mesh_color = c;
218+
data->m_highlight_mesh_color = c;
219219
std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
220220
TileSpec h_tile;
221221
h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;

‎src/mapblock_mesh.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ MeshMakeData::MeshMakeData(IGameDef *gamedef):
4848
m_crack_pos_relative(-1337, -1337, -1337),
4949
m_highlighted_pos_relative(-1337, -1337, -1337),
5050
m_smooth_lighting(false),
51+
m_show_hud(false),
52+
m_highlight_mesh_color(255, 255, 255, 255),
5153
m_gamedef(gamedef)
5254
{}
5355

@@ -330,15 +332,15 @@ static void finalColorBlend(video::SColor& result,
330332

331333
// Emphase blue a bit in darker places
332334
// Each entry of this array represents a range of 8 blue levels
333-
static u8 emphase_blue_when_dark[32] = {
335+
static const u8 emphase_blue_when_dark[32] = {
334336
1, 4, 6, 6, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0,
335337
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
336338
};
337339
b += emphase_blue_when_dark[b / 8];
338340
b = irr::core::clamp (b, 0, 255);
339341

340342
// Artificial light is yellow-ish
341-
static u8 emphase_yellow_when_artificial[16] = {
343+
static const u8 emphase_yellow_when_artificial[16] = {
342344
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 10, 15, 15, 15
343345
};
344346
rg += emphase_yellow_when_artificial[night/16];
@@ -1086,7 +1088,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
10861088

10871089
mapblock_mesh_generate_special(data, collector);
10881090

1089-
m_highlight_mesh_color = data->m_highlight_mesh_color;
1091+
m_highlight_mesh_color = data->m_highlight_mesh_color;
10901092

10911093
/*
10921094
Convert MeshCollector to SMesh

‎src/sky.cpp

+14-18
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,20 @@ void Sky::update(float time_of_day, float time_brightness,
573573
m_clouds_visible = false;
574574
}
575575

576+
video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
577+
m_bgcolor = video::SColor(
578+
255,
579+
bgcolor_bright.getRed() * m_brightness,
580+
bgcolor_bright.getGreen() * m_brightness,
581+
bgcolor_bright.getBlue() * m_brightness);
582+
583+
video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
584+
m_skycolor = video::SColor(
585+
255,
586+
skycolor_bright.getRed() * m_brightness,
587+
skycolor_bright.getGreen() * m_brightness,
588+
skycolor_bright.getBlue() * m_brightness);
589+
576590
// Horizon coloring based on sun and moon direction during sunset and sunrise
577591
video::SColor pointcolor = video::SColor(255, 255, 255, m_bgcolor.getAlpha());
578592
if (m_directional_colored_fog) {
@@ -606,25 +620,7 @@ void Sky::update(float time_of_day, float time_brightness,
606620
// calculate the blend color
607621
pointcolor = m_mix_scolor(pointcolor_moon, pointcolor_sun, pointcolor_blend);
608622
}
609-
}
610-
611-
video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
612-
m_bgcolor = video::SColor(
613-
255,
614-
bgcolor_bright.getRed() * m_brightness,
615-
bgcolor_bright.getGreen() * m_brightness,
616-
bgcolor_bright.getBlue() * m_brightness);
617-
if (m_directional_colored_fog) {
618623
m_bgcolor = m_mix_scolor(m_bgcolor, pointcolor, m_horizon_blend() * 0.5);
619-
}
620-
621-
video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
622-
m_skycolor = video::SColor(
623-
255,
624-
skycolor_bright.getRed() * m_brightness,
625-
skycolor_bright.getGreen() * m_brightness,
626-
skycolor_bright.getBlue() * m_brightness);
627-
if (m_directional_colored_fog) {
628624
m_skycolor = m_mix_scolor(m_skycolor, pointcolor, m_horizon_blend() * 0.25);
629625
}
630626

‎src/sky.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class Sky : public scene::ISceneNode
7979
{
8080
if (!m_sunlight_seen)
8181
return 0;
82-
float x; m_time_of_day >= 0.5 ? x = (1 - m_time_of_day) * 2 : x = m_time_of_day * 2;
82+
float x = m_time_of_day >= 0.5 ? (1 - m_time_of_day) * 2 : m_time_of_day * 2;
83+
8384
if (x <= 0.3)
8485
return 0;
8586
if (x <= 0.4) // when the sun and moon are aligned

0 commit comments

Comments
 (0)
Please sign in to comment.