Guard GridComponent against arbitrarily high grid sizes (#1135)

Also do bounds checking at runtime in the controller for safety.
This commit is contained in:
Nicholas Van Sickle
2021-06-03 20:09:04 -07:00
committed by GitHub
parent f39460e617
commit 34449e2fc9
3 changed files with 11 additions and 6 deletions
@@ -54,13 +54,14 @@ namespace AZ
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &GridComponentConfig::m_gridSize, "Grid Size", "Grid width and depth")
->Attribute(AZ::Edit::Attributes::Min, 0.0f)
->Attribute(AZ::Edit::Attributes::Min, GridComponentController::MinGridSize)
->Attribute(AZ::Edit::Attributes::Max, GridComponentController::MaxGridSize)
->Attribute(AZ::Edit::Attributes::Suffix, " m")
->DataElement(AZ::Edit::UIHandlers::Default, &GridComponentConfig::m_primarySpacing, "Primary Grid Spacing", "Amount of space between grid lines")
->Attribute(AZ::Edit::Attributes::Min, 0.01f)
->Attribute(AZ::Edit::Attributes::Min, GridComponentController::MinSpacing)
->Attribute(AZ::Edit::Attributes::Suffix, " m")
->DataElement(AZ::Edit::UIHandlers::Default, &GridComponentConfig::m_secondarySpacing, "Secondary Grid Spacing", "Amount of space between sub-grid lines")
->Attribute(AZ::Edit::Attributes::Min, 0.01f)
->Attribute(AZ::Edit::Attributes::Min, GridComponentController::MinSpacing)
->Attribute(AZ::Edit::Attributes::Suffix, " m")
->DataElement(AZ::Edit::UIHandlers::Color, &GridComponentConfig::m_axisColor, "Axis Color", "Color of the grid axis")
->DataElement(AZ::Edit::UIHandlers::Color, &GridComponentConfig::m_primaryColor, "Primary Color", "Color of the primary grid lines")
@@ -115,7 +115,7 @@ namespace AZ
void GridComponentController::SetSize(float gridSize)
{
m_configuration.m_gridSize = gridSize;
m_configuration.m_gridSize = AZStd::clamp(gridSize, MinGridSize, MaxGridSize);
m_dirty = true;
}
@@ -126,7 +126,7 @@ namespace AZ
void GridComponentController::SetPrimarySpacing(float gridPrimarySpacing)
{
m_configuration.m_primarySpacing = gridPrimarySpacing;
m_configuration.m_primarySpacing = AZStd::max(gridPrimarySpacing, MinSpacing);
m_dirty = true;
}
@@ -137,7 +137,7 @@ namespace AZ
void GridComponentController::SetSecondarySpacing(float gridSecondarySpacing)
{
m_configuration.m_secondarySpacing = gridSecondarySpacing;
m_configuration.m_secondarySpacing = AZStd::max(gridSecondarySpacing, MinSpacing);
m_dirty = true;
}
@@ -46,6 +46,10 @@ namespace AZ
void SetConfiguration(const GridComponentConfig& config);
const GridComponentConfig& GetConfiguration() const;
static constexpr float MinGridSize = 0.0f;
static constexpr float MaxGridSize = 1000000.0f;
static constexpr float MinSpacing = 0.01f;
private:
AZ_DISABLE_COPY(GridComponentController);