From 76812510a103e17c8ae74128fd2c66c2b6659aad Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 25 Sep 2019 16:18:23 +0200 Subject: [PATCH] Core/GuillotineBinPack: Prevent heap allocation when calling Insert with multiple rectangles --- ChangeLog.md | 1 + src/Nazara/Core/GuillotineBinPack.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index a1f22e9e8..f5a1edf45 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -192,6 +192,7 @@ Nazara Engine: - Added x and y mouse position to MouseWheelEvent - Added SimpleTextDrawer::[Get|Set]MaxLineWidth (which does line wrap) - TypeTag helper struct now includes a Type using +- GuillotineBinPack::Insert overload taking multiple rectangles no longer does a heap allocation Nazara Development Kit: - Added ImageWidget (#139) diff --git a/src/Nazara/Core/GuillotineBinPack.cpp b/src/Nazara/Core/GuillotineBinPack.cpp index 9ebae4bbb..ef8e2f953 100644 --- a/src/Nazara/Core/GuillotineBinPack.cpp +++ b/src/Nazara/Core/GuillotineBinPack.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -302,7 +303,8 @@ namespace Nz bool GuillotineBinPack::Insert(Rectui* rects, bool* flipped, bool* inserted, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod) { - std::vector remainingRects(count); // Position of the rectangle + Nz::StackVector remainingRects = NazaraStackVector(Rectui*, count); // Position of the rectangle + remainingRects.resize(count); for (unsigned int i = 0; i < count; ++i) remainingRects[i] = &rects[i];