1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Merge branch 'get_rid_of_asserts_in_esm' into 'master'

Replace all asserts in components/esm[34] with throw

See merge request OpenMW/openmw!3069
This commit is contained in:
psi29a 2023-05-28 09:14:08 +00:00
commit 052972033c
11 changed files with 25 additions and 27 deletions

View File

@ -93,7 +93,8 @@ namespace ESM
{ {
int currentValue; int currentValue;
esm.getT(currentValue); esm.getT(currentValue);
assert(currentValue >= 0); if (currentValue < 0)
esm.fail("currentValue is less than 0");
rawConnections.push_back(static_cast<size_t>(currentValue)); rawConnections.push_back(static_cast<size_t>(currentValue));
} }

View File

@ -1,5 +1,3 @@
#include <cassert>
#include "npcstats.hpp" #include "npcstats.hpp"
#include "esmreader.hpp" #include "esmreader.hpp"

View File

@ -1,6 +1,5 @@
#include "variant.hpp" #include "variant.hpp"
#include <cassert>
#include <stdexcept> #include <stdexcept>
#include "esmreader.hpp" #include "esmreader.hpp"

View File

@ -30,7 +30,6 @@
//#undef NDEBUG //#undef NDEBUG
//#endif //#endif
//#include <cassert>
#include <stdexcept> #include <stdexcept>
#include "reader.hpp" #include "reader.hpp"

View File

@ -30,7 +30,6 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <cassert>
#include <cstring> #include <cstring>
#include <iostream> // FIXME #include <iostream> // FIXME
#include <sstream> #include <sstream>
@ -163,7 +162,8 @@ void ESM4::Creature::load(ESM4::Reader& reader)
break; 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; std::uint32_t nift;
reader.get(nift); reader.get(nift);
if (nift) if (nift)

View File

@ -30,7 +30,6 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <cassert>
#include <stdexcept> #include <stdexcept>
#include <iostream> // FIXME: debug only #include <iostream> // FIXME: debug only
@ -104,7 +103,8 @@ void ESM4::Land::load(ESM4::Reader& reader)
BTXT base; BTXT base;
if (reader.getExact(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); reader.adjustFormId(base.formId);
mTextures[base.quadrant].base = std::move(base); mTextures[base.quadrant].base = std::move(base);
@ -126,7 +126,8 @@ void ESM4::Land::load(ESM4::Reader& reader)
} }
reader.get(layer.texture); reader.get(layer.texture);
reader.adjustFormId(layer.texture.formId); 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 #if 0
FormId txt = layer.texture.formId; FormId txt = layer.texture.formId;
std::map<FormId, int>::iterator lb = uniqueTextures.lower_bound(txt); std::map<FormId, int>::iterator lb = uniqueTextures.lower_bound(txt);
@ -149,11 +150,12 @@ void ESM4::Land::load(ESM4::Reader& reader)
} }
case ESM4::SUB_VTXT: 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); int count = (int)reader.subRecordHeader().dataSize / sizeof(ESM4::Land::VTXT);
assert((reader.subRecordHeader().dataSize % sizeof(ESM4::Land::VTXT)) == 0 if ((reader.subRecordHeader().dataSize % sizeof(ESM4::Land::VTXT)) != 0)
&& "ESM4::LAND VTXT data size error"); throw std::runtime_error("ESM4::LAND VTXT data size error");
if (count) if (count)
{ {
@ -182,8 +184,8 @@ void ESM4::Land::load(ESM4::Reader& reader)
case ESM4::SUB_VTEX: // only in Oblivion? case ESM4::SUB_VTEX: // only in Oblivion?
{ {
int count = (int)reader.subRecordHeader().dataSize / sizeof(FormId32); int count = (int)reader.subRecordHeader().dataSize / sizeof(FormId32);
assert( if ((reader.subRecordHeader().dataSize % sizeof(FormId32)) != 0)
(reader.subRecordHeader().dataSize % sizeof(FormId32)) == 0 && "ESM4::LAND VTEX data size error"); throw std::runtime_error("ESM4::LAND VTEX data size error");
if (count) if (count)
{ {

View File

@ -30,7 +30,6 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <cassert>
#include <stdexcept> #include <stdexcept>
//#include <iostream> // FIXME: debugging only //#include <iostream> // 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) if ((reader.esmVersion() == ESM::VER_094 || reader.esmVersion() == ESM::VER_170)
&& subHdr.dataSize == 2) // FO3 is VER_094 but dataSize 3 && subHdr.dataSize == 2) // FO3 is VER_094 but dataSize 3
{ {
// assert(subHdr.dataSize == 2 && "LTEX unexpected HNAM size");
reader.get(mHavokFriction); reader.get(mHavokFriction);
reader.get(mHavokRestitution); reader.get(mHavokRestitution);
} }
else 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(mHavokMaterial);
reader.get(mHavokFriction); reader.get(mHavokFriction);
reader.get(mHavokRestitution); reader.get(mHavokRestitution);

View File

@ -30,7 +30,6 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <cassert>
#include <stdexcept> #include <stdexcept>
#include <iostream> // FIXME: debugging only #include <iostream> // FIXME: debugging only
@ -288,7 +287,8 @@ void ESM4::Navigation::load(ESM4::Reader& reader)
#endif #endif
} }
reader.get(count); reader.get(count);
assert(count == 1 && "expected separator"); if (count != 1)
throw std::runtime_error("expected separator");
reader.get(node); // HACK reader.get(node); // HACK
std::vector<FormId> preferredPaths; std::vector<FormId> preferredPaths;
@ -299,7 +299,9 @@ void ESM4::Navigation::load(ESM4::Reader& reader)
#endif #endif
reader.get(count); // HACK reader.get(count); // HACK
assert(count == 10 && "expected 0xa"); if (count != 10)
throw std::runtime_error("expected 0xa");
std::uint32_t index; std::uint32_t index;
for (std::uint32_t i = 0; i < count; ++i) for (std::uint32_t i = 0; i < count; ++i)
{ {

View File

@ -26,7 +26,6 @@
*/ */
#include "loadnavm.hpp" #include "loadnavm.hpp"
#include <cassert>
#include <cstring> #include <cstring>
#include <stdexcept> #include <stdexcept>
@ -180,7 +179,8 @@ void ESM4::NavMesh::NVNMstruct::load(ESM4::Reader& reader)
} }
triSegments.push_back(indices); 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 0
if (triSegments.size() != divisor*divisor) if (triSegments.size() != divisor*divisor)
std::cout << "divisor " << std::dec << divisor << ", segments " << triSegments.size() << //std::endl; std::cout << "divisor " << std::dec << divisor << ", segments " << triSegments.size() << //std::endl;

View File

@ -30,7 +30,6 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <cassert>
#include <stdexcept> #include <stdexcept>
//#include <iostream> // FIXME: debug only //#include <iostream> // FIXME: debug only
@ -85,7 +84,8 @@ void ESM4::Region::load(ESM4::Reader& reader)
break; break;
case ESM4::SUB_RDMP: 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); reader.getLocalizedString(mMapName);
break; break;
} }
@ -111,7 +111,6 @@ void ESM4::Region::load(ESM4::Reader& reader)
} }
case ESM4::SUB_RDSD: // Possibly the same as RDSA case ESM4::SUB_RDSD: // Possibly the same as RDSA
{ {
// assert(mData.type == RDAT_Map && "REGN unexpected data type");
if (mData.type != RDAT_Sound) if (mData.type != RDAT_Sound)
throw std::runtime_error( throw std::runtime_error(
"ESM4::REGN::load - unexpected data type " + ESM::printName(subHdr.typeId)); "ESM4::REGN::load - unexpected data type " + ESM::printName(subHdr.typeId));

View File

@ -30,7 +30,6 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include <cassert>
#include <stdexcept> #include <stdexcept>
#include <iostream> // FIXME: debugging only #include <iostream> // FIXME: debugging only