Skip to content

Commit c2aa84c

Browse files
committed
[VK] Fixed insertion sort in VKDeviceMemory::InsertBlock() (fixes #225).
The function didn't handle the case when the inserted block must be inserted at the beginning.
1 parent 57ff237 commit c2aa84c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sources/Renderer/Vulkan/Memory/VKDeviceMemory.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,26 @@ VKDeviceMemoryRegion* VKDeviceMemory::InsertBlock(VKDeviceMemoryRegionPtr&& regi
271271
{
272272
VKDeviceMemoryRegion* regionRef = region.get();
273273

274-
/* Add block by insertion sort */
275274
if (!blocks_.empty())
276275
{
276+
/* Add block by insertion sort starting search from the right */
277277
for (auto it = blocks_.rbegin(); it != blocks_.rend(); ++it)
278278
{
279279
if ((*it)->GetOffset() < region->GetOffset())
280280
{
281281
blocks_.insert(it.base(), std::move(region));
282-
break;
282+
return regionRef;
283283
}
284284
}
285+
286+
/* Insert block at the beginning */
287+
blocks_.insert(blocks_.begin(), std::move(region));
285288
}
286289
else
290+
{
291+
/* Insert first block */
287292
blocks_.emplace_back(std::move(region));
293+
}
288294

289295
return regionRef;
290296
}

0 commit comments

Comments
 (0)