From ca1a83e21d0cdb4b3443252b11789bd8ecff3c86 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 8 Feb 2025 18:11:23 +0000 Subject: Improve logging and fault detection during mesh mutation --- game/geoData.cpp | 34 +++++++++++++++++++++++++++++----- game/geoData.h | 3 ++- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'game') diff --git a/game/geoData.cpp b/game/geoData.cpp index 4cfcf6d..816ce03 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -6,6 +6,9 @@ #include #include #include +#ifndef NDEBUG +# include +#endif GeoData GeoData::loadFromAsciiGrid(const std::filesystem::path & input) @@ -554,6 +557,7 @@ GeoData::setHeights(const std::span triangleStrip, const } return std::nullopt; }; + sanityCheck(); // Cut along each edge of triangleStrip AB, AC, BC, BD, CD, CE etc std::map *> boundaryTriangles; @@ -602,6 +606,16 @@ GeoData::setHeights(const std::span triangleStrip, const })) { continue; } +#ifndef NDEBUG + CLOG(start); + CLOG(startPoint); + CLOG(end); + CLOG(endPoint); + for (const auto v : vv_range(start)) { + CLOG(point(v)); + } +#endif + sanityCheck(); throw std::runtime_error( std::format("Could not navigate to ({}, {}, {})", endPoint.x, endPoint.y, endPoint.z)); } @@ -655,6 +669,7 @@ GeoData::setHeights(const std::span triangleStrip, const } done.insert(heh); } + sanityCheck(); std::vector out; auto surfaceStripWalk @@ -686,11 +701,20 @@ GeoData::getGeneration() const } void -GeoData::sanityCheck() const +GeoData::sanityCheck(const std::source_location & loc) const { - if (!std::ranges::all_of(faces(), [this](const auto face) { - return triangle<2>(face).isUp(); - })) { - throw std::logic_error("Upside down faces detected"); + if (const auto upSideDown = std::ranges::count_if(faces(), [this](const auto face) { + if (!triangle<2>(face).isUp()) { +#ifndef NDEBUG + for (const auto v : fv_range(face)) { + CLOG(point(v)); + } +#endif + return true; + } + return false; + }) > 0) { + throw std::logic_error(std::format( + "{} upside down faces detected - checked from {}:{}", upSideDown, loc.function_name(), loc.line())); } } diff --git a/game/geoData.h b/game/geoData.h index 390a443..7c11b07 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -115,7 +116,7 @@ public: return property(surface, handle); } - void sanityCheck() const; + void sanityCheck(const std::source_location & = std::source_location::current()) const; protected: template -- cgit v1.2.3