forked from organicmaps/organicmaps
Fix bug with adding invalid mwm file to maps container in MwmSet.
This commit is contained in:
parent
92236836ac
commit
d907bcc454
2 changed files with 24 additions and 13 deletions
|
@ -23,6 +23,12 @@ namespace
|
|||
};
|
||||
} // unnamed namespace
|
||||
|
||||
MwmInfo::MwmInfo() : m_lockCount(0), m_status(STATUS_REMOVED)
|
||||
{
|
||||
// Important: STATUS_REMOVED - is the default value.
|
||||
// Apply STATUS_ACTIVE before adding to maps container.
|
||||
}
|
||||
|
||||
MwmSet::MwmLock::MwmLock(MwmSet const & mwmSet, MwmId mwmId)
|
||||
: m_mwmSet(mwmSet), m_id(mwmId), m_pValue(mwmSet.LockValue(mwmId))
|
||||
{
|
||||
|
@ -84,9 +90,8 @@ MwmSet::MwmId MwmSet::GetFreeId()
|
|||
if (m_info[i].m_status == MwmInfo::STATUS_REMOVED)
|
||||
return i;
|
||||
}
|
||||
|
||||
m_info.push_back(MwmInfo());
|
||||
m_info.back().m_status = MwmInfo::STATUS_REMOVED;
|
||||
m_info.back().m_lockCount = 0;
|
||||
m_name.push_back(string());
|
||||
return size;
|
||||
}
|
||||
|
@ -123,14 +128,18 @@ int MwmSet::Add(string const & fileName, m2::RectD & r)
|
|||
return -1;
|
||||
}
|
||||
|
||||
// this function can throw an exception for bad mwm file
|
||||
MwmInfo info;
|
||||
int const version = GetInfo(fileName, info);
|
||||
|
||||
info.m_status = MwmInfo::STATUS_ACTIVE;
|
||||
|
||||
MwmId const id = GetFreeId();
|
||||
m_name[id] = fileName;
|
||||
memset(&m_info[id], 0, sizeof(MwmInfo));
|
||||
int const version = GetInfo(fileName, m_info[id]);
|
||||
m_info[id].m_lockCount = 0;
|
||||
m_info[id].m_status = MwmInfo::STATUS_ACTIVE;
|
||||
m_info[id] = info;
|
||||
|
||||
r = m_info[id].m_limitRect;
|
||||
r = info.m_limitRect;
|
||||
ASSERT ( r.IsValid(), () );
|
||||
return version;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,13 +9,15 @@
|
|||
#include "../std/vector.hpp"
|
||||
|
||||
|
||||
// Information about stored mwm.
|
||||
/// Information about stored mwm.
|
||||
class MwmInfo
|
||||
{
|
||||
public:
|
||||
m2::RectD m_limitRect; // Limit rect of mwm.
|
||||
uint8_t m_minScale; // Min zoom level of mwm.
|
||||
uint8_t m_maxScale; // Max zoom level of mwm.
|
||||
MwmInfo();
|
||||
|
||||
m2::RectD m_limitRect; ///< Limit rect of mwm.
|
||||
uint8_t m_minScale; ///< Min zoom level of mwm.
|
||||
uint8_t m_maxScale; ///< Max zoom level of mwm.
|
||||
|
||||
// Does this MwmInfo represent a valid Mwm?
|
||||
inline bool isValid() const { return (m_status == STATUS_ACTIVE); }
|
||||
|
@ -25,8 +27,8 @@ private:
|
|||
friend class MwmSet;
|
||||
|
||||
enum Status { STATUS_ACTIVE = 0, STATUS_TO_REMOVE = 1, STATUS_REMOVED = 2 };
|
||||
uint8_t m_lockCount; // Number of locks.
|
||||
uint8_t m_status; //
|
||||
uint8_t m_lockCount; ///< Number of locks.
|
||||
uint8_t m_status; ///< Current country status.
|
||||
};
|
||||
|
||||
class MwmSet
|
||||
|
|
Loading…
Add table
Reference in a new issue