Fixed dynamic vertex/index buffer leak warning. Issue #263.

This commit is contained in:
Branimir Karadžić 2015-02-21 21:51:06 -08:00
parent c3112bce2a
commit 4685fdeca3
2 changed files with 39 additions and 4 deletions

View file

@ -123,6 +123,11 @@ void VectorDisplay::resize(uint16_t _width, uint16_t _height)
void VectorDisplay::teardown() void VectorDisplay::teardown()
{ {
for (size_t i = 0; i < m_vertexBuffers.size(); ++i)
{
bgfx::destroyDynamicVertexBuffer(m_vertexBuffers[i]);
}
teardownResDependent(); teardownResDependent();
bgfx::destroyProgram(m_drawToScreenShader); bgfx::destroyProgram(m_drawToScreenShader);
@ -728,7 +733,7 @@ bool VectorDisplay::setDecaySteps(int _steps)
{ {
for (size_t i = 0; i < m_vertexBuffers.size(); ++i) for (size_t i = 0; i < m_vertexBuffers.size(); ++i)
{ {
destroyDynamicVertexBuffer(m_vertexBuffers[i]); bgfx::destroyDynamicVertexBuffer(m_vertexBuffers[i]);
} }
m_vertexBuffers.clear(); m_vertexBuffers.clear();

View file

@ -1738,6 +1738,20 @@ namespace bgfx
m_free.push_back(Free(_ptr, _size) ); m_free.push_back(Free(_ptr, _size) );
} }
uint64_t remove()
{
BX_CHECK(0 == m_used.size(), "");
if (0 < m_free.size() )
{
Free free = m_free.front();
m_free.pop_front();
return free.m_ptr;
}
return 0;
}
uint64_t alloc(uint32_t _size) uint64_t alloc(uint32_t _size)
{ {
for (FreeList::iterator it = m_free.begin(), itEnd = m_free.end(); it != itEnd; ++it) for (FreeList::iterator it = m_free.begin(), itEnd = m_free.end(); it != itEnd; ++it)
@ -1776,7 +1790,7 @@ namespace bgfx
} }
} }
void compact() bool compact()
{ {
m_free.sort(); m_free.sort();
@ -1793,6 +1807,8 @@ namespace bgfx
++next; ++next;
} }
} }
return 0 == m_used.size();
} }
private: private:
@ -2165,7 +2181,14 @@ namespace bgfx
else else
{ {
m_dynIndexBufferAllocator.free(uint64_t(dib.m_handle.idx)<<32 | dib.m_offset); m_dynIndexBufferAllocator.free(uint64_t(dib.m_handle.idx)<<32 | dib.m_offset);
m_dynIndexBufferAllocator.compact(); if (m_dynIndexBufferAllocator.compact() )
{
for (uint64_t ptr = m_dynIndexBufferAllocator.remove(); 0 != ptr; ptr = m_dynIndexBufferAllocator.remove() )
{
IndexBufferHandle handle = { uint16_t(ptr>>32) };
destroyIndexBuffer(handle);
}
}
} }
m_dynamicIndexBufferHandle.free(_handle.idx); m_dynamicIndexBufferHandle.free(_handle.idx);
@ -2310,7 +2333,14 @@ namespace bgfx
else else
{ {
m_dynVertexBufferAllocator.free(uint64_t(dvb.m_handle.idx)<<32 | dvb.m_offset); m_dynVertexBufferAllocator.free(uint64_t(dvb.m_handle.idx)<<32 | dvb.m_offset);
m_dynVertexBufferAllocator.compact(); if (m_dynVertexBufferAllocator.compact() )
{
for (uint64_t ptr = m_dynVertexBufferAllocator.remove(); 0 != ptr; ptr = m_dynVertexBufferAllocator.remove() )
{
VertexBufferHandle handle = { uint16_t(ptr>>32) };
destroyVertexBuffer(handle);
}
}
} }
m_dynamicVertexBufferHandle.free(_handle.idx); m_dynamicVertexBufferHandle.free(_handle.idx);