From 128b58ca08a2840233242cbf0b196c44a9efd3d5 Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Sat, 4 Jan 2025 22:45:54 +0100 Subject: [PATCH] add some check if adt failed loading when calculating extents --- src/noggit/MapTile.cpp | 56 ++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/src/noggit/MapTile.cpp b/src/noggit/MapTile.cpp index 031c0e5e..4235a9ae 100644 --- a/src/noggit/MapTile.cpp +++ b/src/noggit/MapTile.cpp @@ -975,8 +975,11 @@ void MapTile::remove_model(uint32_t uid) { uids.erase(it); - const auto obj = _world->get_model(uid).value(); - auto instance = std::get(obj); + const auto obj = _world->get_model(uid); + if (!obj.has_value()) + return; + + auto instance = std::get(obj.value()); auto& instances = object_instances[instance->instance_model()]; auto it2 = std::find(instances.begin(), instances.end(), instance); @@ -1032,8 +1035,11 @@ void MapTile::add_model(uint32_t uid) { uids.push_back(uid); - const auto& obj = _world->get_model(uid).value(); - auto instance = std::get(obj); + const auto obj = _world->get_model(uid); + if (!obj) + return; + + auto instance = std::get(obj.value()); object_instances[instance->instance_model()].push_back(instance); if (instance->finishedLoading()) @@ -1584,27 +1590,27 @@ void MapTile::setVertexColorImage(QImage const& baseimage, int mode, bool tiledE case 1: // Add { 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].y = std::min(2.0, std::max(0.0, 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].x = std::min(2.0f, std::max(0.0f, colors[idx].x + color.redF() * 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.0f, std::max(0.0f, colors[idx].z + color.blueF() * 2.f)); break; } case 2: // Subtract { 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].y = std::min(2.0, std::max(0.0, 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].x = std::min(2.0f, std::max(0.0f, colors[idx].x - color.redF() * 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.0f, std::max(0.0f, colors[idx].z - color.blueF() * 2.f)); break; } case 3: // Multiply { 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].y = std::min(2.0, std::max(0.0, 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].x = std::min(2.0f, std::max(0.0f, colors[idx].x * color.redF() * 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.0f, std::max(0.0f, colors[idx].z * color.blueF() * 2.f)); break; } } @@ -1702,6 +1708,18 @@ void MapTile::recalcExtents() _extents[0].y = std::numeric_limits::max(); _extents[1].y = std::numeric_limits::lowest(); + if (!finishedLoading()) + { + _extents_dirty = true; + return; + } + + if (loading_failed()) + { + _extents_dirty = false; + return; + } + for (int i = 0; i < 256; ++i) { unsigned x = i / 16; @@ -1853,6 +1871,18 @@ void MapTile::recalcCombinedExtents() if (!_combined_extents_dirty) return; + if (!finishedLoading()) + { + _combined_extents_dirty = true; + return; + } + + if (loading_failed()) + { + _combined_extents_dirty = false; + return; + } + // ensure all extents are updated { recalcExtents();