Browse Source

Use a free area index parameter instead of IntRect in AreaAllocator::SplitRect() to make it clear that the freeAreas_ is being manipulated inside the function.

Lasse Öörni 10 years ago
parent
commit
c24d709ee1
2 changed files with 6 additions and 3 deletions
  1. 5 2
      Source/Urho3D/Math/AreaAllocator.cpp
  2. 1 1
      Source/Urho3D/Math/AreaAllocator.h

+ 5 - 2
Source/Urho3D/Math/AreaAllocator.cpp

@@ -149,7 +149,7 @@ bool AreaAllocator::Allocate(int width, int height, int& x, int& y)
         // Remove the reserved area from all free areas
         for (unsigned i = 0; i < freeAreas_.Size();)
         {
-            if (SplitRect(freeAreas_[i], reserved))
+            if (SplitRect(i, reserved))
                 freeAreas_.Erase(i);
             else
                 ++i;
@@ -161,8 +161,11 @@ bool AreaAllocator::Allocate(int width, int height, int& x, int& y)
     return true;
 }
 
-bool AreaAllocator::SplitRect(const IntRect& original, const IntRect& reserve)
+bool AreaAllocator::SplitRect(unsigned freeAreaIndex, const IntRect& reserve)
 {
+    // Make a copy, as the vector will be modified
+    IntRect original = freeAreas_[freeAreaIndex];
+
     if (reserve.right_ > original.left_ && reserve.left_ < original.right_ && reserve.bottom_ > original.top_ &&
         reserve.top_ < original.bottom_)
     {

+ 1 - 1
Source/Urho3D/Math/AreaAllocator.h

@@ -54,7 +54,7 @@ public:
 
 private:
     /// Remove space from a free rectangle. Return true if the original rectangle should be erased from the free list. Not called in fast mode.
-    bool SplitRect(const IntRect& original, const IntRect& reserve);
+    bool SplitRect(unsigned freeAreaIndex, const IntRect& reserve);
     /// Clean up redundant free space. Not called in fast mode.
     void Cleanup();