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
macos_ci
psi29a 2 years ago
commit 052972033c

@ -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<size_t>(currentValue));
}

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

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

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

@ -30,7 +30,6 @@
#undef NDEBUG
#endif
#include <cassert>
#include <cstring>
#include <iostream> // FIXME
#include <sstream>
@ -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)

@ -30,7 +30,6 @@
#undef NDEBUG
#endif
#include <cassert>
#include <stdexcept>
#include <iostream> // 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<FormId, int>::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)
{

@ -30,7 +30,6 @@
#undef NDEBUG
#endif
#include <cassert>
#include <stdexcept>
//#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)
&& 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);

@ -30,7 +30,6 @@
#undef NDEBUG
#endif
#include <cassert>
#include <stdexcept>
#include <iostream> // 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<FormId> 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)
{

@ -26,7 +26,6 @@
*/
#include "loadnavm.hpp"
#include <cassert>
#include <cstring>
#include <stdexcept>
@ -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;

@ -30,7 +30,6 @@
#undef NDEBUG
#endif
#include <cassert>
#include <stdexcept>
//#include <iostream> // 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));

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

Loading…
Cancel
Save