From b4c67dba8c457b70acaa1b9bc1445beeb6606394 Mon Sep 17 00:00:00 2001 From: milek7 Date: Sun, 23 Sep 2018 18:58:46 +0200 Subject: [PATCH] fix crash on trying to render empty chunks --- openglgeometrybank.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/openglgeometrybank.cpp b/openglgeometrybank.cpp index 5e57aa0f..87d9ee9b 100644 --- a/openglgeometrybank.cpp +++ b/openglgeometrybank.cpp @@ -150,7 +150,9 @@ void calculate_tangent(vertex_array &vertices, int type) gfx::geometry_handle geometry_bank::create( gfx::vertex_array const &Vertices, unsigned int const Type ) { - if( true == Vertices.empty() ) { return { 0, 0 }; } + if( true == Vertices.empty() ) { + return { 0, 0 }; + } m_chunks.emplace_back( Vertices, Type ); // NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication @@ -456,22 +458,23 @@ void geometrybank_manager::draw(const std::vector::iterato if (begin == end) return; - auto &run_bank = bank(*begin); + auto run_bank = begin->bank; std::vector::iterator run_begin = begin; std::vector::iterator it; for (it = begin; it != end; it++) { - if (bank(*it) != run_bank) + if (it->bank != run_bank) { - run_bank.first->draw(run_begin, it); - run_bank = bank(*it); + if (run_bank != 0) + m_geometrybanks[run_bank - 1].first->draw(run_begin, it); + run_bank = it->bank; run_begin = it; } } - if (run_begin != it) - run_bank.first->draw(run_begin, it); + if (run_begin != it && run_bank != 0) + m_geometrybanks[run_bank - 1].first->draw(run_begin, it); } // provides direct access to vertex data of specfied chunk