From c98c5322139c2cc8d3a961586fe8e954f4dcb74e Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 27 May 2023 16:07:04 +0200 Subject: [PATCH] Replace all asserts in components/esm[34] with throw --- components/esm3/loadpgrd.cpp | 3 ++- components/esm3/npcstats.cpp | 2 -- components/esm3/variant.cpp | 1 - components/esm4/loadclas.cpp | 1 - components/esm4/loadcrea.cpp | 4 ++-- components/esm4/loadland.cpp | 18 ++++++++++-------- components/esm4/loadltex.cpp | 5 ++--- components/esm4/loadnavi.cpp | 8 +++++--- components/esm4/loadnavm.cpp | 4 ++-- components/esm4/loadregn.cpp | 5 ++--- components/esm4/loadtes4.cpp | 1 - 11 files changed, 25 insertions(+), 27 deletions(-) diff --git a/components/esm3/loadpgrd.cpp b/components/esm3/loadpgrd.cpp index 807929cdeb..ea0b53d8d2 100644 --- a/components/esm3/loadpgrd.cpp +++ b/components/esm3/loadpgrd.cpp @@ -93,7 +93,8 @@ namespace ESM { int currentValue; esm.getT(currentValue); - assert(currentValue >= 0); + if (currentValue < 0) + esm.fail("currentValue is less than 0"); rawConnections.push_back(static_cast(currentValue)); } diff --git a/components/esm3/npcstats.cpp b/components/esm3/npcstats.cpp index 7234afbed2..0f271556bb 100644 --- a/components/esm3/npcstats.cpp +++ b/components/esm3/npcstats.cpp @@ -1,5 +1,3 @@ -#include - #include "npcstats.hpp" #include "esmreader.hpp" diff --git a/components/esm3/variant.cpp b/components/esm3/variant.cpp index 6850b41e56..f45fe262c4 100644 --- a/components/esm3/variant.cpp +++ b/components/esm3/variant.cpp @@ -1,6 +1,5 @@ #include "variant.hpp" -#include #include #include "esmreader.hpp" diff --git a/components/esm4/loadclas.cpp b/components/esm4/loadclas.cpp index a5c571e9a2..ec3b37989e 100644 --- a/components/esm4/loadclas.cpp +++ b/components/esm4/loadclas.cpp @@ -30,7 +30,6 @@ //#undef NDEBUG //#endif -//#include #include #include "reader.hpp" diff --git a/components/esm4/loadcrea.cpp b/components/esm4/loadcrea.cpp index 953b1e9a6c..6af84f0a84 100644 --- a/components/esm4/loadcrea.cpp +++ b/components/esm4/loadcrea.cpp @@ -30,7 +30,6 @@ #undef NDEBUG #endif -#include #include #include // FIXME #include @@ -163,7 +162,8 @@ void ESM4::Creature::load(ESM4::Reader& reader) break; } - assert(subHdr.dataSize == 4 && "CREA NIFT datasize error"); + if (subHdr.dataSize != 4) + throw std::runtime_error("CREA NIFT datasize error"); std::uint32_t nift; reader.get(nift); if (nift) diff --git a/components/esm4/loadland.cpp b/components/esm4/loadland.cpp index ccbfe66f44..7bc0f8bbde 100644 --- a/components/esm4/loadland.cpp +++ b/components/esm4/loadland.cpp @@ -30,7 +30,6 @@ #undef NDEBUG #endif -#include #include #include // FIXME: debug only @@ -104,7 +103,8 @@ void ESM4::Land::load(ESM4::Reader& reader) BTXT base; if (reader.getExact(base)) { - assert(base.quadrant < 4 && "base texture quadrant index error"); + if (base.quadrant >= 4) + throw std::runtime_error("base texture quadrant index error"); reader.adjustFormId(base.formId); mTextures[base.quadrant].base = std::move(base); @@ -126,7 +126,8 @@ void ESM4::Land::load(ESM4::Reader& reader) } reader.get(layer.texture); reader.adjustFormId(layer.texture.formId); - assert(layer.texture.quadrant < 4 && "additional texture quadrant index error"); + if (layer.texture.quadrant >= 4) + throw std::runtime_error("additional texture quadrant index error"); #if 0 FormId txt = layer.texture.formId; std::map::iterator lb = uniqueTextures.lower_bound(txt); @@ -149,11 +150,12 @@ void ESM4::Land::load(ESM4::Reader& reader) } case ESM4::SUB_VTXT: { - assert(currentAddQuad != -1 && "VTXT without ATXT found"); + if (currentAddQuad == -1) + throw std::runtime_error("VTXT without ATXT found"); int count = (int)reader.subRecordHeader().dataSize / sizeof(ESM4::Land::VTXT); - assert((reader.subRecordHeader().dataSize % sizeof(ESM4::Land::VTXT)) == 0 - && "ESM4::LAND VTXT data size error"); + if ((reader.subRecordHeader().dataSize % sizeof(ESM4::Land::VTXT)) != 0) + throw std::runtime_error("ESM4::LAND VTXT data size error"); if (count) { @@ -182,8 +184,8 @@ void ESM4::Land::load(ESM4::Reader& reader) case ESM4::SUB_VTEX: // only in Oblivion? { int count = (int)reader.subRecordHeader().dataSize / sizeof(FormId32); - assert( - (reader.subRecordHeader().dataSize % sizeof(FormId32)) == 0 && "ESM4::LAND VTEX data size error"); + if ((reader.subRecordHeader().dataSize % sizeof(FormId32)) != 0) + throw std::runtime_error("ESM4::LAND VTEX data size error"); if (count) { diff --git a/components/esm4/loadltex.cpp b/components/esm4/loadltex.cpp index 866ae49d28..af9b6efa6a 100644 --- a/components/esm4/loadltex.cpp +++ b/components/esm4/loadltex.cpp @@ -30,7 +30,6 @@ #undef NDEBUG #endif -#include #include //#include // FIXME: debugging only @@ -64,13 +63,13 @@ void ESM4::LandTexture::load(ESM4::Reader& reader) if ((reader.esmVersion() == ESM::VER_094 || reader.esmVersion() == ESM::VER_170) && subHdr.dataSize == 2) // FO3 is VER_094 but dataSize 3 { - // assert(subHdr.dataSize == 2 && "LTEX unexpected HNAM size"); reader.get(mHavokFriction); reader.get(mHavokRestitution); } else { - assert(subHdr.dataSize == 3 && "LTEX unexpected HNAM size"); + if (subHdr.dataSize != 3) + throw std::runtime_error("LTEX unexpected HNAM size, expected 3"); reader.get(mHavokMaterial); reader.get(mHavokFriction); reader.get(mHavokRestitution); diff --git a/components/esm4/loadnavi.cpp b/components/esm4/loadnavi.cpp index 95e6a730c8..7e50cce818 100644 --- a/components/esm4/loadnavi.cpp +++ b/components/esm4/loadnavi.cpp @@ -30,7 +30,6 @@ #undef NDEBUG #endif -#include #include #include // FIXME: debugging only @@ -288,7 +287,8 @@ void ESM4::Navigation::load(ESM4::Reader& reader) #endif } reader.get(count); - assert(count == 1 && "expected separator"); + if (count != 1) + throw std::runtime_error("expected separator"); reader.get(node); // HACK std::vector preferredPaths; @@ -299,7 +299,9 @@ void ESM4::Navigation::load(ESM4::Reader& reader) #endif reader.get(count); // HACK - assert(count == 10 && "expected 0xa"); + if (count != 10) + throw std::runtime_error("expected 0xa"); + std::uint32_t index; for (std::uint32_t i = 0; i < count; ++i) { diff --git a/components/esm4/loadnavm.cpp b/components/esm4/loadnavm.cpp index 2cbd45a588..720857547d 100644 --- a/components/esm4/loadnavm.cpp +++ b/components/esm4/loadnavm.cpp @@ -26,7 +26,6 @@ */ #include "loadnavm.hpp" -#include #include #include @@ -180,7 +179,8 @@ void ESM4::NavMesh::NVNMstruct::load(ESM4::Reader& reader) } triSegments.push_back(indices); } - assert(triSegments.size() == divisor * divisor && "tiangle segments size is not the square of divisor"); + if (triSegments.size() != divisor * divisor) + throw std::runtime_error("Triangle segments size is not the square of divisor"); #if 0 if (triSegments.size() != divisor*divisor) std::cout << "divisor " << std::dec << divisor << ", segments " << triSegments.size() << //std::endl; diff --git a/components/esm4/loadregn.cpp b/components/esm4/loadregn.cpp index a2eeebce68..11938dcb5c 100644 --- a/components/esm4/loadregn.cpp +++ b/components/esm4/loadregn.cpp @@ -30,7 +30,6 @@ #undef NDEBUG #endif -#include #include //#include // FIXME: debug only @@ -85,7 +84,8 @@ void ESM4::Region::load(ESM4::Reader& reader) break; case ESM4::SUB_RDMP: { - assert(mData.type == RDAT_Map && "REGN unexpected data type"); + if (mData.type != RDAT_Map) + throw std::runtime_error("REGN unexpected data type"); reader.getLocalizedString(mMapName); break; } @@ -111,7 +111,6 @@ void ESM4::Region::load(ESM4::Reader& reader) } case ESM4::SUB_RDSD: // Possibly the same as RDSA { - // assert(mData.type == RDAT_Map && "REGN unexpected data type"); if (mData.type != RDAT_Sound) throw std::runtime_error( "ESM4::REGN::load - unexpected data type " + ESM::printName(subHdr.typeId)); diff --git a/components/esm4/loadtes4.cpp b/components/esm4/loadtes4.cpp index 27d55a9dde..9c67548687 100644 --- a/components/esm4/loadtes4.cpp +++ b/components/esm4/loadtes4.cpp @@ -30,7 +30,6 @@ #undef NDEBUG #endif -#include #include #include // FIXME: debugging only