Merge branch 'esm4_fix' into 'master'

Add a safeguard to load only supported records

Closes #7406

See merge request OpenMW/openmw!3158
revert-6246b479
psi29a 2 years ago
commit a59f22fd30

@ -210,21 +210,28 @@ namespace MWWorld
template <class T, class Id>
RecordId TypedDynamicStore<T, Id>::load(ESM::ESMReader& esm)
{
T record;
bool isDeleted = false;
if constexpr (!ESM::isESM4Rec(T::sRecordId))
{
T record;
bool isDeleted = false;
record.load(esm, isDeleted);
}
std::pair<typename Static::iterator, bool> inserted = mStatic.insert_or_assign(record.mId, record);
if (inserted.second)
mShared.push_back(&inserted.first->second);
std::pair<typename Static::iterator, bool> inserted = mStatic.insert_or_assign(record.mId, record);
if (inserted.second)
mShared.push_back(&inserted.first->second);
if constexpr (std::is_same_v<Id, ESM::RefId>)
return RecordId(record.mId, isDeleted);
if constexpr (std::is_same_v<Id, ESM::RefId>)
return RecordId(record.mId, isDeleted);
else
return RecordId();
}
else
return RecordId();
{
std::stringstream msg;
msg << "Can not load record of type ESM::REC_" << getRecNameString(T::sRecordId).toStringView()
<< ": ESM::ESMReader can load only ESM3 records.";
throw std::runtime_error(msg.str());
}
}
template <class T, class Id>

Loading…
Cancel
Save