From 82b640e71c61773fdcdb5592d6abc7fa8f15d71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 24 Feb 2016 21:23:45 -0800 Subject: [PATCH] 27-terrain: Fixed crash at exit. --- examples/27-terrain/terrain.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/27-terrain/terrain.cpp b/examples/27-terrain/terrain.cpp index 71ab88aa1..067684b19 100644 --- a/examples/27-terrain/terrain.cpp +++ b/examples/27-terrain/terrain.cpp @@ -169,9 +169,14 @@ class Terrain : public entry::AppI bgfx::destroyProgram(m_terrainProgram); bgfx::destroyProgram(m_terrainHeightTextureProgram); - BX_FREE(entry::getAllocator(), m_terrain.m_vertices); - BX_FREE(entry::getAllocator(), m_terrain.m_indices); - BX_FREE(entry::getAllocator(), m_terrain.m_heightMap); + /// When data is passed to bgfx via makeRef we need to make + /// sure library is done with it before freeing memory blocks. + bgfx::frame(); + + bx::AllocatorI* allocator = entry::getAllocator(); + BX_FREE(allocator, m_terrain.m_vertices); + BX_FREE(allocator, m_terrain.m_indices); + BX_FREE(allocator, m_terrain.m_heightMap); // Shutdown bgfx. bgfx::shutdown();