From 0d1c8b8d315bb4e603fcac9ea8920cce759f7993 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 4 Feb 2019 14:50:14 +0100 Subject: [PATCH] Fix CircularBuffer push_back method. --- src/openrct2/core/CircularBuffer.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/openrct2/core/CircularBuffer.h b/src/openrct2/core/CircularBuffer.h index ff18ad7eae..e897a69fae 100644 --- a/src/openrct2/core/CircularBuffer.h +++ b/src/openrct2/core/CircularBuffer.h @@ -78,16 +78,30 @@ public: void push_back(const value_type& val) { - if (_size == capacity()) + if (_size == 0) { - _head = (_head + 1) % capacity(); + _elements[_head] = val; + _tail = _head; + _size++; + } + else if (_size != capacity()) + { + _tail++; + if (_tail == capacity()) + _tail = 0; + _size++; + _elements[_tail] = val; } else { - _size++; + _head++; + if (_head == capacity()) + _head = 0; + _tail++; + if (_tail == capacity()) + _tail = 0; + _elements[_tail] = val; } - _elements[_tail] = val; - _tail = (_tail + 1) % capacity(); } private: