Skip to content
0.2.0-dev Download ZIP
48 lines ·1.8 KB Raw
1diff --git a/thirdparty/offset_allocator/offsetAllocator.cpp b/thirdparty/offset_allocator/offsetAllocator.cpp
2--- a/thirdparty/offset_allocator/offsetAllocator.cpp
3+++ b/thirdparty/offset_allocator/offsetAllocator.cpp
4@@ -170,7 +170,7 @@ namespace OffsetAllocator
5 {
6 m_freeStorage = 0;
7 m_usedBinsTop = 0;
8- m_freeOffset = m_maxAllocs - 1;
9+ m_freeOffset = m_maxAllocs;
10
11 for (uint32 i = 0 ; i < NUM_TOP_BINS; i++)
12 m_usedBins[i] = 0;
13@@ -181,13 +181,13 @@ namespace OffsetAllocator
14 if (m_nodes) delete[] m_nodes;
15 if (m_freeNodes) delete[] m_freeNodes;
16
17- m_nodes = new Node[m_maxAllocs];
18- m_freeNodes = new NodeIndex[m_maxAllocs];
19+ m_nodes = new Node[m_maxAllocs + 1];
20+ m_freeNodes = new NodeIndex[m_maxAllocs + 1];
21
22 // Freelist is a stack. Nodes in inverse order so that [0] pops first.
23- for (uint32 i = 0; i < m_maxAllocs; i++)
24+ for (uint32 i = 0; i < m_maxAllocs + 1; i++)
25 {
26- m_freeNodes[i] = m_maxAllocs - i - 1;
27+ m_freeNodes[i] = m_maxAllocs - i;
28 }
29
30 // Start state: Whole storage as one big node
31@@ -204,7 +204,7 @@ namespace OffsetAllocator
32 Allocation Allocator::allocate(uint32 size)
33 {
34 // Out of allocations?
35- if (m_freeOffset == 0)
36+ if (m_freeOffset == Allocation::NO_SPACE)
37 {
38 return {.offset = Allocation::NO_SPACE, .metadata = Allocation::NO_SPACE};
39 }
40@@ -452,7 +452,7 @@ namespace OffsetAllocator
41 uint32 freeStorage = 0;
42
43 // Out of allocations? -> Zero free space
44- if (m_freeOffset > 0)
45+ if ((m_nodes != nullptr) && (m_freeOffset != Allocation::NO_SPACE))
46 {
47 freeStorage = m_freeStorage;
48 if (m_usedBinsTop)