Skip to content

Commit

Permalink
#5893: Fix crash after resizing the client side buffers, seems like o…
Browse files Browse the repository at this point in the history
…penGL is accessing the vertex data after the old buffer has gone out of business.
  • Loading branch information
codereader committed Feb 6, 2022
1 parent d143178 commit 34ee551
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libs/render/ContinuousBuffer.h
Expand Up @@ -29,6 +29,7 @@ class ContinuousBuffer
static constexpr std::size_t GrowthRate = 1; // 100% growth each time

std::vector<ElementType> _buffer;
std::vector<ElementType> _inactiveBuffer;

struct SlotInfo
{
Expand Down Expand Up @@ -212,7 +213,13 @@ class ContinuousBuffer

// Allocate more memory
auto additionalSize = std::max(_buffer.size() * GrowthRate, requiredSize);
_buffer.resize(_buffer.size() + additionalSize);
auto newSize = _buffer.size() + additionalSize;

// Park the old data in the inactive buffer, some GL thread might still access it
_inactiveBuffer = std::move(_buffer);

_buffer = _inactiveBuffer;
_buffer.resize(newSize);

// Use the right most slot for our requirement, then cut up the rest of the space
auto& rightmostFreeSlot = _slots[rightmostFreeSlotIndex];
Expand Down

0 comments on commit 34ee551

Please sign in to comment.