Add safety checks for door state

pull/556/head
Andrei Kortunov 5 years ago
parent 2f133000e0
commit 88a695f251

@ -34,7 +34,7 @@ namespace MWClass
class DoorCustomData : public MWWorld::CustomData class DoorCustomData : public MWWorld::CustomData
{ {
public: public:
MWWorld::DoorState mDoorState; MWWorld::DoorState mDoorState = MWWorld::DoorState::Idle;
virtual MWWorld::CustomData *clone() const; virtual MWWorld::CustomData *clone() const;
@ -344,8 +344,6 @@ namespace MWClass
if (!ptr.getRefData().getCustomData()) if (!ptr.getRefData().getCustomData())
{ {
std::unique_ptr<DoorCustomData> data(new DoorCustomData); std::unique_ptr<DoorCustomData> data(new DoorCustomData);
data->mDoorState = MWWorld::DoorState::Idle;
ptr.getRefData().setCustomData(data.release()); ptr.getRefData().setCustomData(data.release());
} }
} }

@ -3,6 +3,8 @@
#include "esmreader.hpp" #include "esmreader.hpp"
#include "esmwriter.hpp" #include "esmwriter.hpp"
#include <components/debug/debuglog.hpp>
namespace ESM namespace ESM
{ {
@ -12,12 +14,20 @@ namespace ESM
mDoorState = 0; mDoorState = 0;
esm.getHNOT (mDoorState, "ANIM"); esm.getHNOT (mDoorState, "ANIM");
if (mDoorState < 0 || mDoorState > 2)
Log(Debug::Warning) << "Dropping invalid door state (" << mDoorState << ") for door \"" << mRef.mRefID << "\"";
} }
void DoorState::save(ESMWriter &esm, bool inInventory) const void DoorState::save(ESMWriter &esm, bool inInventory) const
{ {
ObjectState::save(esm, inInventory); ObjectState::save(esm, inInventory);
if (mDoorState < 0 || mDoorState > 2)
{
Log(Debug::Warning) << "Dropping invalid door state (" << mDoorState << ") for door \"" << mRef.mRefID << "\"";
return;
}
if (mDoorState != 0) if (mDoorState != 0)
esm.writeHNT ("ANIM", mDoorState); esm.writeHNT ("ANIM", mDoorState);
} }

@ -9,7 +9,7 @@ namespace ESM
struct DoorState : public ObjectState struct DoorState : public ObjectState
{ {
int mDoorState; int mDoorState = 0;
virtual void load (ESMReader &esm); virtual void load (ESMReader &esm);
virtual void save (ESMWriter &esm, bool inInventory = false) const; virtual void save (ESMWriter &esm, bool inInventory = false) const;

Loading…
Cancel
Save