1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Schematic: Properly deal with before/after node resolving and document (#11011)

This fixes an out-of-bounds index access when the node resolver was already applied to the schematic (i.e. biome decoration).
Also improves the handling of the two cases: prior node resolving (m_nodenames), and after node resolving (manual lookup)
This commit is contained in:
SmallJoker 2021-03-20 13:02:15 +01:00 committed by GitHub
parent a8cc3bdb08
commit 05719913ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 154 additions and 87 deletions

View file

@ -56,6 +56,8 @@ void TestNodeResolver::runTests(IGameDef *gamedef)
class Foobar : public NodeResolver {
public:
friend class TestNodeResolver; // m_ndef
void resolveNodeNames();
content_t test_nr_node1;

View file

@ -66,13 +66,14 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef)
std::stringstream ss(std::ios_base::binary |
std::ios_base::in | std::ios_base::out);
std::vector<std::string> names;
names.emplace_back("foo");
names.emplace_back("bar");
names.emplace_back("baz");
names.emplace_back("qux");
Schematic schem, schem2;
Schematic schem;
{
std::vector<std::string> &names = schem.m_nodenames;
names.emplace_back("foo");
names.emplace_back("bar");
names.emplace_back("baz");
names.emplace_back("qux");
}
schem.flags = 0;
schem.size = size;
@ -83,18 +84,21 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef)
for (s16 y = 0; y != size.Y; y++)
schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;
UASSERT(schem.serializeToMts(&ss, names));
UASSERT(schem.serializeToMts(&ss));
ss.seekg(0);
names.clear();
UASSERT(schem2.deserializeFromMts(&ss, &names));
Schematic schem2;
UASSERT(schem2.deserializeFromMts(&ss));
UASSERTEQ(size_t, names.size(), 4);
UASSERTEQ(std::string, names[0], "foo");
UASSERTEQ(std::string, names[1], "bar");
UASSERTEQ(std::string, names[2], "baz");
UASSERTEQ(std::string, names[3], "qux");
{
std::vector<std::string> &names = schem2.m_nodenames;
UASSERTEQ(size_t, names.size(), 4);
UASSERTEQ(std::string, names[0], "foo");
UASSERTEQ(std::string, names[1], "bar");
UASSERTEQ(std::string, names[2], "baz");
UASSERTEQ(std::string, names[3], "qux");
}
UASSERT(schem2.size == size);
for (size_t i = 0; i != volume; i++)
@ -120,14 +124,14 @@ void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef)
for (s16 y = 0; y != size.Y; y++)
schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;
std::vector<std::string> names;
std::vector<std::string> &names = schem.m_nodenames;
names.emplace_back("air");
names.emplace_back("default:lava_source");
names.emplace_back("default:glass");
std::ostringstream ss(std::ios_base::binary);
UASSERT(schem.serializeToLua(&ss, names, false, 0));
UASSERT(schem.serializeToLua(&ss, false, 0));
UASSERTEQ(std::string, ss.str(), expected_lua_output);
}
@ -159,6 +163,8 @@ void TestSchematic::testFileSerializeDeserialize(const NodeDefManager *ndef)
schem1.slice_probs[0] = 80;
schem1.slice_probs[1] = 160;
schem1.slice_probs[2] = 240;
// Node resolving happened manually.
schem1.m_resolve_done = true;
for (size_t i = 0; i != volume; i++) {
content_t c = content_map[test_schem2_data[i]];