Limit light_source in the engine (#4814)
authorjuhdanad <juhdanad@gmail.com>
Mon, 28 Nov 2016 08:43:33 +0000 (09:43 +0100)
committerZeno- <kde.psych@gmail.com>
Mon, 28 Nov 2016 08:43:33 +0000 (18:43 +1000)
Since light_source>15 causes crash, it must be limited.

src/nodedef.cpp
src/script/common/c_content.cpp
src/voxelalgorithms.cpp

index 39ea1a60e2b6734e20233b9067584aff442a1a58..ccbb42c667e4de507e70bc352e94f861f0b7a113 100644 (file)
@@ -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);
@@ -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);
index f20a65903c5015f1d40cd7a129ea773e1e02ef6f..5417448953056e04a612931eb76ba7e2b9ac4800 100644 (file)
@@ -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);
 
index 55f0d1c986d820a9184b2b5d48b2c6117f0d912b..93cc33acc0a5cf7bcf57b8a5f9100f198ebf92a9 100644 (file)
@@ -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));
        }