1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Handle writing to unloaded blocks in MMVManip::blitBackAll()

This could happen before and would just silently discard the data,
but now that Lua can create VManips without loading from map beforehand
we definitely need to handle this case.
This commit is contained in:
sfan5 2025-05-25 19:16:58 +02:00
parent aa1bab2156
commit 9f7501d20a
3 changed files with 22 additions and 17 deletions

View file

@ -789,20 +789,10 @@ void MMVManip::initialEmerge(v3s16 p_min, v3s16 p_max, bool load_if_inexistent)
if (auto it = had_blocks.find(p); it != had_blocks.end() && it->second)
continue;
MapBlock *block;
bool block_data_inexistent = false;
{
TimeTaker timer2("emerge load", &emerge_load_time);
block = m_map->getBlockNoCreateNoEx(p);
if (!block)
block_data_inexistent = true;
else
block->copyTo(*this);
}
if(block_data_inexistent)
{
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
if (block) {
block->copyTo(*this);
} else {
if (load_if_inexistent && !blockpos_over_max_limit(p)) {
block = m_map->emergeBlock(p, true);
assert(block);
@ -862,6 +852,8 @@ void MMVManip::blitBackAll(std::map<v3s16, MapBlock*> *modified_blocks,
return;
assert(m_map);
size_t nload = 0;
// Copy all the blocks with data back to the map
const auto loaded_blocks = getCoveredBlocks();
for (auto &it : loaded_blocks) {
@ -869,7 +861,18 @@ void MMVManip::blitBackAll(std::map<v3s16, MapBlock*> *modified_blocks,
continue;
v3s16 p = it.first;
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
if (!block || (!overwrite_generated && block->isGenerated()))
if (!block) {
if (!blockpos_over_max_limit(p)) {
block = m_map->emergeBlock(p, true);
nload++;
}
}
if (!block) {
warningstream << "blitBackAll: Couldn't load block " << p
<< " to write data to map" << std::endl;
continue;
}
if (!overwrite_generated && block->isGenerated())
continue;
block->copyFrom(*this);
@ -879,6 +882,10 @@ void MMVManip::blitBackAll(std::map<v3s16, MapBlock*> *modified_blocks,
if(modified_blocks)
(*modified_blocks)[p] = block;
}
if (nload > 0) {
verbosestream << "blitBackAll: " << nload << " blocks had to be loaded for writing" << std::endl;
}
}
MMVManip *MMVManip::clone() const

View file

@ -15,7 +15,6 @@
Debug stuff
*/
u64 emerge_time = 0;
u64 emerge_load_time = 0;
VoxelManipulator::~VoxelManipulator()
{

View file

@ -34,7 +34,6 @@ class NodeDefManager;
Debug stuff
*/
extern u64 emerge_time;
extern u64 emerge_load_time;
/*
This class resembles aabbox3d<s16> a lot, but has inclusive