mirror of
https://github.com/nicbarker/clay.git
synced 2026-05-31 21:47:15 +00:00
[Core] Fix self referencing node bug in hashmap pruning
This commit is contained in:
parent
8c6ab72890
commit
1dc7473d47
1 changed files with 10 additions and 10 deletions
20
clay.h
20
clay.h
|
|
@ -4750,29 +4750,29 @@ Clay_RenderCommandArray Clay_EndLayout(float deltaTime) {
|
|||
for (int i = 0; i < context->layoutElementsHashMap.capacity; ++i) {
|
||||
int32_t currentElementIndex = context->layoutElementsHashMap.internalArray[i];
|
||||
int32_t previousElementIndex = -1;
|
||||
int32_t listDepth = 0;
|
||||
while (currentElementIndex != -1) {
|
||||
Clay_LayoutElementHashMapItem* currentItem = Clay__LayoutElementHashMapItemArray_Get(&context->layoutElementsHashMapInternal, currentElementIndex);
|
||||
int32_t nextIndex = currentItem->nextIndex;
|
||||
// Needs to be pruned
|
||||
if (currentItem->generation <= context->generation) {
|
||||
// Delete the underlying item and add it to the freelist
|
||||
Clay__LayoutElementHashMapItemArray_Set(&context->layoutElementsHashMapInternal, currentElementIndex, CLAY__INIT(Clay_LayoutElementHashMapItem) { .nextIndex = -1 });
|
||||
Clay__int32_tArray_Add(&context->layoutElementsHashMapFreeList, currentElementIndex);
|
||||
// If it's the very top of the bucket, rewrite the first bucket pointer
|
||||
if (listDepth == 0) {
|
||||
if (previousElementIndex == -1) {
|
||||
Clay__int32_tArray_Set(&context->layoutElementsHashMap, i, nextIndex);
|
||||
listDepth--;
|
||||
currentElementIndex = nextIndex;
|
||||
previousElementIndex = -1;
|
||||
} else {
|
||||
// Rewrite previous pointer
|
||||
Clay_LayoutElementHashMapItem* previousItem = Clay__LayoutElementHashMapItemArray_Get(&context->layoutElementsHashMapInternal, previousElementIndex);
|
||||
previousItem->nextIndex = nextIndex;
|
||||
currentElementIndex = nextIndex;
|
||||
}
|
||||
// Delete the underlying item and add it to the freelist
|
||||
Clay__LayoutElementHashMapItemArray_Set(&context->layoutElementsHashMapInternal, currentElementIndex, CLAY__INIT(Clay_LayoutElementHashMapItem) { .nextIndex = -1 });
|
||||
Clay__int32_tArray_Add(&context->layoutElementsHashMapFreeList, currentElementIndex);
|
||||
} else {
|
||||
previousElementIndex = currentElementIndex;
|
||||
currentElementIndex = nextIndex;
|
||||
}
|
||||
|
||||
previousElementIndex = currentElementIndex;
|
||||
currentElementIndex = nextIndex;
|
||||
listDepth++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue