2
0
Эх сурвалжийг харах

Additional bounds checking on vector property display

Signed-off-by: gadams3 <[email protected]>
gadams3 3 жил өмнө
parent
commit
6084e907b5

+ 2 - 2
Gems/GraphCanvas/Code/Source/Components/NodePropertyDisplays/VectorNodePropertyDisplay.cpp

@@ -281,10 +281,10 @@ namespace GraphCanvas
     void VectorNodePropertyDisplay::SubmitValue()
     {
         AzQtComponents::VectorElement** elements = m_propertyVectorCtrl->getElements();
-        const int elementCount = m_dataInterface->GetElementCount();
+        const int elementCount = m_propertyVectorCtrl->getSize();
         for (int i = 0; i < elementCount; ++i)
         {
-            AzQtComponents::VectorElement* element = elements[i];
+            const AzQtComponents::VectorElement* element = elements[i];
             m_dataInterface->SetValue(i, element->getValue());
         }
         UpdateDisplay();

+ 22 - 26
Gems/GraphModel/Code/Include/GraphModel/Integration/VectorDataInterface.inl

@@ -19,8 +19,7 @@
 namespace GraphModelIntegration
 {
     template<class Type, int ElementCount>
-    class VectorDataInterface
-        : public GraphCanvas::VectorDataInterface
+    class VectorDataInterface : public GraphCanvas::VectorDataInterface
     {
     public:
         AZ_CLASS_ALLOCATOR(VectorDataInterface, AZ::SystemAllocator, 0);
@@ -33,23 +32,17 @@ namespace GraphModelIntegration
 
         const char* GetLabel(int index) const override
         {
-            if (index == 0)
+            switch (index)
             {
+            case 0:
                 return "X";
-            }
-            else if (index == 1)
-            {
+            case 1:
                 return "Y";
-            }
-            else if (index == 2)
-            {
+            case 2:
                 return "Z";
-            }
-            else if (index == 3)
-            {
+            case 3:
                 return "W";
             }
-
             return "???";
         }
         AZStd::string GetStyle() const override
@@ -69,27 +62,30 @@ namespace GraphModelIntegration
         {
             if (GraphModel::SlotPtr slot = m_slot.lock())
             {
-                return slot->GetValue<Type>().GetElement(index);
-            }
-            else
-            {
-                return 0.0;
+                if (index < ElementCount)
+                {
+                    return slot->GetValue<Type>().GetElement(index);
+                }
             }
+            return 0.0;
         }
         void SetValue(int index, double value) override
         {
             if (GraphModel::SlotPtr slot = m_slot.lock())
             {
-                Type vector = slot->GetValue<Type>();
-                if (value != vector.GetElement(index))
+                if (index < ElementCount)
                 {
-                    const GraphCanvas::GraphId graphCanvasSceneId = GetDisplay()->GetSceneId();
-                    GraphCanvas::ScopedGraphUndoBatch undoBatch(graphCanvasSceneId);
+                    Type vector = slot->GetValue<Type>();
+                    if (value != vector.GetElement(index))
+                    {
+                        const GraphCanvas::GraphId graphCanvasSceneId = GetDisplay()->GetSceneId();
+                        GraphCanvas::ScopedGraphUndoBatch undoBatch(graphCanvasSceneId);
 
-                    vector.SetElement(index, aznumeric_cast<float>(value));
-                    slot->SetValue(vector);
-                    GraphControllerNotificationBus::Event(
-                        graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelGraphModified, slot->GetParentNode());
+                        vector.SetElement(index, aznumeric_cast<float>(value));
+                        slot->SetValue(vector);
+                        GraphControllerNotificationBus::Event(
+                            graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelGraphModified, slot->GetParentNode());
+                    }
                 }
             }
         }