Skip to content

Commit

Permalink
Limit light_source in the engine (#4814)
Browse files Browse the repository at this point in the history
Since light_source>15 causes crash, it must be limited.
  • Loading branch information
juhdanad authored and Zeno- committed Nov 28, 2016
1 parent bb06d37 commit 2fe3bf5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/nodedef.cpp
Expand Up @@ -482,6 +482,7 @@ void ContentFeatures::deSerialize(std::istream &is)
liquid_viscosity = readU8(is);
liquid_renewable = readU8(is);
light_source = readU8(is);
light_source = MYMIN(light_source, LIGHT_MAX);
damage_per_second = readU32(is);
node_box.deSerialize(is);
selection_box.deSerialize(is);
Expand Down Expand Up @@ -1442,6 +1443,7 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version)
liquid_alternative_source = deSerializeString(is);
liquid_viscosity = readU8(is);
light_source = readU8(is);
light_source = MYMIN(light_source, LIGHT_MAX);
damage_per_second = readU32(is);
node_box.deSerialize(is);
selection_box.deSerialize(is);
Expand Down
6 changes: 6 additions & 0 deletions src/script/common/c_content.cpp
Expand Up @@ -526,6 +526,12 @@ ContentFeatures read_content_features(lua_State *L, int index)
// Amount of light the node emits
f.light_source = getintfield_default(L, index,
"light_source", f.light_source);
if (f.light_source > LIGHT_MAX) {
warningstream << "Node " << f.name.c_str()
<< " had greater light_source than " << LIGHT_MAX
<< ", it was reduced." << std::endl;
f.light_source = LIGHT_MAX;
}
f.damage_per_second = getintfield_default(L, index,
"damage_per_second", f.damage_per_second);

Expand Down
1 change: 1 addition & 0 deletions src/voxelalgorithms.cpp
Expand Up @@ -264,6 +264,7 @@ struct LightQueue {
const mapblock_v3 &block_pos, MapBlock *block,
direction source_dir)
{
assert(light <= LIGHT_SUN);
lights[light].push_back(
ChangingLight(rel_pos, block_pos, block, source_dir));
}
Expand Down

0 comments on commit 2fe3bf5

Please sign in to comment.