From 5426b655fe1d870847ccab885d35a52fff3b9eb8 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 16 Jul 2016 14:12:15 +0100 Subject: [PATCH] Try combine _freelists when freeing to reduce chance of running out of images. --- src/drawing/Image.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/drawing/Image.cpp b/src/drawing/Image.cpp index 0fab47c9b9..1129cd1380 100644 --- a/src/drawing/Image.cpp +++ b/src/drawing/Image.cpp @@ -99,7 +99,22 @@ static void FreeImageList(uint32 baseImageId, uint32 count) bool contains = AllocatedListContains(baseImageId, count); Guard::Assert(contains); #endif - + + for (auto it = _freeLists.begin(); it != _freeLists.end(); it++) + { + if (it->BaseId + count == baseImageId) + { + it->Count += count; + return; + } + else if (baseImageId + count == it->BaseId) + { + it->BaseId = baseImageId; + it->Count += count; + return; + } + } + // TODO validate that this was an allocated list _freeLists.push_back({ baseImageId, count }); }