1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-06 11:15:33 +00:00

Merge pull request #2642 from akortunov/warnfix2

Add safety checks for door state
This commit is contained in:
Alexei Dobrohotov 2019-12-23 21:22:56 +03:00 committed by GitHub
commit 2693598d82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

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

View file

@ -3,6 +3,8 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/debug/debuglog.hpp>
namespace ESM
{
@ -12,12 +14,20 @@ namespace ESM
mDoorState = 0;
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
{
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)
esm.writeHNT ("ANIM", mDoorState);
}

View file

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