Fixed crash on invalid HazeMode.

This commit is contained in:
Nissim 2017-10-19 13:36:32 -07:00
parent fe286aff83
commit edd256c600
3 changed files with 22 additions and 4 deletions

View file

@ -228,11 +228,21 @@ const std::array<ComponentPair, COMPONENT_MODE_ITEM_COUNT> COMPONENT_MODES = { {
} };
QString EntityItemProperties::getHazeModeAsString() const {
return COMPONENT_MODES[_hazeMode].second;
// return "inherit" if _hazeMode is not valid
if (_hazeMode >= 0 && _hazeMode < COMPONENT_MODE_ITEM_COUNT) {
return COMPONENT_MODES[_hazeMode].second;
} else {
return COMPONENT_MODES[0].second;
}
}
QString EntityItemProperties::getHazeModeString(uint32_t mode) {
return COMPONENT_MODES[mode].second;
// return "inherit" if mode is not valid
if (mode >= 0 && mode < COMPONENT_MODE_ITEM_COUNT) {
return COMPONENT_MODES[mode].second;
} else {
return COMPONENT_MODES[0].second;
}
}
void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) {

View file

@ -44,6 +44,7 @@ ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID) : EntityItem(en
_compoundShapeURL = DEFAULT_COMPOUND_SHAPE_URL;
_backgroundMode = BACKGROUND_MODE_INHERIT;
_hazeMode = (uint32_t)COMPONENT_MODE_INHERIT;
}
EntityItemProperties ZoneEntityItem::getProperties(EntityPropertyFlags desiredProperties) const {
@ -320,8 +321,15 @@ void ZoneEntityItem::resetRenderingPropertiesChanged() {
});
}
#pragma optimize("", off)
void ZoneEntityItem::setHazeMode(const uint32_t value) {
_hazeMode = value;
if (_hazeMode >= 0 && _hazeMode < COMPONENT_MODE_ITEM_COUNT) {
_hazeMode = value;
}
else {
_hazeMode = 0;
}
_hazePropertiesChanged = true;
}

View file

@ -146,7 +146,7 @@ protected:
BackgroundMode _backgroundMode = BACKGROUND_MODE_INHERIT;
uint8_t _hazeMode{ (uint8_t)COMPONENT_MODE_INHERIT };
uint32_t _hazeMode{ (uint32_t)COMPONENT_MODE_INHERIT };
float _hazeRange{ HazePropertyGroup::DEFAULT_HAZE_RANGE };
xColor _hazeColor{ HazePropertyGroup::DEFAULT_HAZE_COLOR };