I’m currently trying to implement a Queue in C++ that I can use from Blueprint.
Problem is, that every time the queue gets destructed, the pointers to the queue elements are broken.
The pointer to head and tail should not get garbage collected as long as the queue references them. Calling functions on the queue works without problems. Only when destructing the queue everything goes boom. Pretty lost here.
To fix it, i created
head = tail = NewObject<UQueueBPElementTail>();
and call it in all functions that need the tail to exist.
and to clear it:
// If there is no tail, we never had elements.
ForEachElement([this](UQueueBPElement*& currentElement) -> void
// We are going to delete the element and thus break the loop.
// To prevent this we need to set the pointer back one element.
UQueueBPElement* previousElement = currentElement->previous;
currentElement = previousElement;
ensure(numElements == 0);
ensure(head == tail);
ensure(tail->previous == nullptr);
ensure(tail->next == nullptr);
ensure(tail->GetClass() == UQueueBPElementTail::StaticClass());