add some check if adt failed loading when calculating extents

This commit is contained in:
T1ti
2025-01-04 22:45:54 +01:00
parent ba21431e0b
commit 128b58ca08

View File

@@ -975,8 +975,11 @@ void MapTile::remove_model(uint32_t uid)
{ {
uids.erase(it); uids.erase(it);
const auto obj = _world->get_model(uid).value(); const auto obj = _world->get_model(uid);
auto instance = std::get<selected_object_type>(obj); if (!obj.has_value())
return;
auto instance = std::get<selected_object_type>(obj.value());
auto& instances = object_instances[instance->instance_model()]; auto& instances = object_instances[instance->instance_model()];
auto it2 = std::find(instances.begin(), instances.end(), instance); auto it2 = std::find(instances.begin(), instances.end(), instance);
@@ -1032,8 +1035,11 @@ void MapTile::add_model(uint32_t uid)
{ {
uids.push_back(uid); uids.push_back(uid);
const auto& obj = _world->get_model(uid).value(); const auto obj = _world->get_model(uid);
auto instance = std::get<selected_object_type>(obj); if (!obj)
return;
auto instance = std::get<selected_object_type>(obj.value());
object_instances[instance->instance_model()].push_back(instance); object_instances[instance->instance_model()].push_back(instance);
if (instance->finishedLoading()) if (instance->finishedLoading())
@@ -1584,27 +1590,27 @@ void MapTile::setVertexColorImage(QImage const& baseimage, int mode, bool tiledE
case 1: // Add case 1: // Add
{ {
auto color = image.pixelColor((k * 16) + x, (l * 16) + y); auto color = image.pixelColor((k * 16) + x, (l * 16) + y);
colors[idx].x = std::min(2.0, std::max(0.0, colors[idx].x + color.redF() * 2.f)); colors[idx].x = std::min(2.0f, std::max(0.0f, colors[idx].x + color.redF() * 2.f));
colors[idx].y = std::min(2.0, std::max(0.0, colors[idx].y + color.greenF() * 2.f)); colors[idx].y = std::min(2.0f, std::max(0.0f, colors[idx].y + color.greenF() * 2.f));
colors[idx].z = std::min(2.0, std::max(0.0, colors[idx].z + color.blueF() * 2.f)); colors[idx].z = std::min(2.0f, std::max(0.0f, colors[idx].z + color.blueF() * 2.f));
break; break;
} }
case 2: // Subtract case 2: // Subtract
{ {
auto color = image.pixelColor((k * 16) + x, (l * 16) + y); auto color = image.pixelColor((k * 16) + x, (l * 16) + y);
colors[idx].x = std::min(2.0, std::max(0.0, colors[idx].x - color.redF() * 2.f)); colors[idx].x = std::min(2.0f, std::max(0.0f, colors[idx].x - color.redF() * 2.f));
colors[idx].y = std::min(2.0, std::max(0.0, colors[idx].y - color.greenF() * 2.f)); colors[idx].y = std::min(2.0f, std::max(0.0f, colors[idx].y - color.greenF() * 2.f));
colors[idx].z = std::min(2.0, std::max(0.0, colors[idx].z - color.blueF() * 2.f)); colors[idx].z = std::min(2.0f, std::max(0.0f, colors[idx].z - color.blueF() * 2.f));
break; break;
} }
case 3: // Multiply case 3: // Multiply
{ {
auto color = image.pixelColor((k * 16) + x, (l * 16) + y); auto color = image.pixelColor((k * 16) + x, (l * 16) + y);
colors[idx].x = std::min(2.0, std::max(0.0, colors[idx].x * color.redF() * 2.f)); colors[idx].x = std::min(2.0f, std::max(0.0f, colors[idx].x * color.redF() * 2.f));
colors[idx].y = std::min(2.0, std::max(0.0, colors[idx].y * color.greenF() * 2.f)); colors[idx].y = std::min(2.0f, std::max(0.0f, colors[idx].y * color.greenF() * 2.f));
colors[idx].z = std::min(2.0, std::max(0.0, colors[idx].z * color.blueF() * 2.f)); colors[idx].z = std::min(2.0f, std::max(0.0f, colors[idx].z * color.blueF() * 2.f));
break; break;
} }
} }
@@ -1702,6 +1708,18 @@ void MapTile::recalcExtents()
_extents[0].y = std::numeric_limits<float>::max(); _extents[0].y = std::numeric_limits<float>::max();
_extents[1].y = std::numeric_limits<float>::lowest(); _extents[1].y = std::numeric_limits<float>::lowest();
if (!finishedLoading())
{
_extents_dirty = true;
return;
}
if (loading_failed())
{
_extents_dirty = false;
return;
}
for (int i = 0; i < 256; ++i) for (int i = 0; i < 256; ++i)
{ {
unsigned x = i / 16; unsigned x = i / 16;
@@ -1853,6 +1871,18 @@ void MapTile::recalcCombinedExtents()
if (!_combined_extents_dirty) if (!_combined_extents_dirty)
return; return;
if (!finishedLoading())
{
_combined_extents_dirty = true;
return;
}
if (loading_failed())
{
_combined_extents_dirty = false;
return;
}
// ensure all extents are updated // ensure all extents are updated
{ {
recalcExtents(); recalcExtents();