1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 19:45:33 +00:00

Fix a bug in ESMStore code that checks for duplicate record insertions

This commit is contained in:
scrawl 2014-05-11 00:10:28 +02:00
parent 3ad28ec5aa
commit 07d9845aa0

View file

@ -166,16 +166,17 @@ namespace MWWorld
template <class T>
const T *insert(const T &x) {
std::ostringstream id;
id << "$dynamic" << mDynamicCount++;
Store<T> &store = const_cast<Store<T> &>(get<T>());
if (store.search(x.mId) != 0) {
if (store.search(id.str()) != 0) {
std::ostringstream msg;
msg << "Try to override existing record '" << x.mId << "'";
msg << "Try to override existing record '" << id.str() << "'";
throw std::runtime_error(msg.str());
}
T record = x;
std::ostringstream id;
id << "$dynamic" << mDynamicCount++;
record.mId = id.str();
T *ptr = store.insert(record);
@ -189,10 +190,13 @@ namespace MWWorld
template <class T>
const T *insertStatic(const T &x) {
std::ostringstream id;
id << "$dynamic" << mDynamicCount++;
Store<T> &store = const_cast<Store<T> &>(get<T>());
if (store.search(x.mId) != 0) {
if (store.search(id.str()) != 0) {
std::ostringstream msg;
msg << "Try to override existing record '" << x.mId << "'";
msg << "Try to override existing record '" << id.str() << "'";
throw std::runtime_error(msg.str());
}
T record = x;
@ -225,17 +229,18 @@ namespace MWWorld
template <>
inline const ESM::NPC *ESMStore::insert<ESM::NPC>(const ESM::NPC &npc) {
std::ostringstream id;
id << "$dynamic" << mDynamicCount++;
if (Misc::StringUtils::ciEqual(npc.mId, "player")) {
return mNpcs.insert(npc);
} else if (mNpcs.search(npc.mId) != 0) {
} else if (mNpcs.search(id.str()) != 0) {
std::ostringstream msg;
msg << "Try to override existing record '" << npc.mId << "'";
msg << "Try to override existing record '" << id.str() << "'";
throw std::runtime_error(msg.str());
}
ESM::NPC record = npc;
std::ostringstream id;
id << "$dynamic" << mDynamicCount++;
record.mId = id.str();
ESM::NPC *ptr = mNpcs.insert(record);