Don't fall on empty Sections

This commit is contained in:
Roman Shishkin 2019-05-16 19:17:09 +03:00
parent 6719ccdbe1
commit 281603dc5a
3 changed files with 15 additions and 6 deletions

View file

@ -1,5 +1,6 @@
/*
Copyright (c) 2015, 2018, Matthias Schiffer <mschiffer@universe-factory.net>
Copyright (c) 2019, Roman Shishkin <spark@uwtech.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without

View file

@ -1,5 +1,6 @@
/*
Copyright (c) 2015-2018, Matthias Schiffer <mschiffer@universe-factory.net>
Copyright (c) 2019, Roman Shishkin <spark@uwtech.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -54,9 +55,11 @@ Chunk::Chunk(const ChunkData *data) {
for (auto &sTag : *sectionsTag) {
auto s = std::dynamic_pointer_cast<const NBT::CompoundTag>(sTag);
std::unique_ptr<Section> section = Section::makeSection(s);
size_t Y = section->getY();
sections.resize(Y);
sections.push_back(std::move(section));
if (section != nullptr) {
size_t Y = section->getY();
sections.resize(Y);
sections.push_back(std::move(section));
}
}
}

View file

@ -1,5 +1,6 @@
/*
Copyright (c) 2015-2018, Matthias Schiffer <mschiffer@universe-factory.net>
Copyright (c) 2019, Roman Shishkin <spark@uwtech.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -49,10 +50,14 @@ std::unique_ptr<Section> Section::makeSection(const std::shared_ptr<const NBT::C
return std::unique_ptr<Section>(new PaletteSection(section, std::move(blockStates), palette));
}
std::shared_ptr<const NBT::ByteArrayTag> blocks = assertValue(section->get<NBT::ByteArrayTag>("Blocks"));
std::shared_ptr<const NBT::ByteArrayTag> data = assertValue(section->get<NBT::ByteArrayTag>("Data"));
std::shared_ptr<const NBT::ByteArrayTag> blocks = section->get<NBT::ByteArrayTag>("BlockStates");
if (blocks) {
std::shared_ptr<const NBT::ByteArrayTag> data = assertValue(section->get<NBT::ByteArrayTag>("Data"));
return std::unique_ptr<Section>(new LegacySection(section, std::move(blocks), std::move(data)));
return std::unique_ptr<Section>(new LegacySection(section, std::move(blocks), std::move(data)));
}
return nullptr;
}