Fixed crash by empty index buffer

This commit is contained in:
r.kuznetsov 2015-04-20 17:48:50 +03:00
parent 3d6c6713ca
commit 624edbbce7
5 changed files with 38 additions and 7 deletions

View file

@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "drape/sdf_image.h"
#include "drape/sdf_image.hpp"
#include "base/math.hpp"
#include "base/scope_guard.hpp"

View file

@ -17,13 +17,19 @@ public:
CallbacksWrapper(GLState const & state, RefPointer<OverlayHandle> overlay)
: m_state(state)
, m_overlay(overlay)
, m_vaoChanged(false)
{
}
void SetVAO(RefPointer<VertexArrayBuffer> buffer)
{
// invocation with non-null VAO will cause to invalid range of indices.
// It means that VAO has been changed during batching
if (!m_buffer.IsNull())
m_vaoChanged = true;
m_buffer = buffer;
m_indicesRange.m_idxStart = m_buffer->GetIndexCount();
}
bool IsVAOFilled() const
@ -74,11 +80,23 @@ public:
return m_state;
}
IndicesRange const & Finish()
{
if (!m_vaoChanged)
m_indicesRange.m_idxCount = m_buffer->GetIndexCount() - m_indicesRange.m_idxStart;
else
m_indicesRange = IndicesRange();
return m_indicesRange;
}
private:
GLState const & m_state;
RefPointer<VertexArrayBuffer> m_buffer;
RefPointer<OverlayHandle> m_overlay;
vector<uint16_t> m_indexStorage;
RefPointer<OverlayHandle> m_overlay;
vector<uint16_t> m_indexStorage;
IndicesRange m_indicesRange;
bool m_vaoChanged;
};
////////////////////////////////////////////////////////////////
@ -203,7 +221,6 @@ IndicesRange Batcher::InsertTriangles(GLState const & state, RefPointer<Attribut
RefPointer<RenderBucket> bucket = GetBucket(state);
RefPointer<VertexArrayBuffer> vao = bucket->GetBuffer();
IndicesRange range;
range.m_idxStart = vao->GetIndexCount();
MasterPointer<OverlayHandle> handle(transferHandle);
@ -223,12 +240,13 @@ IndicesRange Batcher::InsertTriangles(GLState const & state, RefPointer<Attribut
batch.SetIsCanDevideStreams(handle.IsNull());
batch.SetVertexStride(vertexStride);
batch.BatchData(params);
range = wrapper.Finish();
}
if (!handle.IsNull())
bucket->AddOverlayHandle(handle.Move());
range.m_idxCount = vao->GetIndexCount() - range.m_idxStart;
return range;
}

View file

@ -50,7 +50,7 @@ void VertexArrayBuffer::Preflush()
void VertexArrayBuffer::Render()
{
RenderRange({ 0, GetIndexBuffer().GetCurrentSize() });
RenderRange(IndicesRange(0, GetIndexBuffer().GetCurrentSize()));
}
void VertexArrayBuffer::RenderRange(IndicesRange const & range)

View file

@ -17,6 +17,16 @@ struct IndicesRange
{
uint16_t m_idxStart;
uint16_t m_idxCount;
IndicesRange()
: m_idxStart(0), m_idxCount(0)
{}
IndicesRange(uint16_t idxStart, uint16_t idxCount)
: m_idxStart(idxStart), m_idxCount(idxCount)
{}
bool IsValid() const { return m_idxCount != 0; }
};
class VertexArrayBuffer

View file

@ -144,6 +144,7 @@ void MyPosition::CacheAccuracySector(dp::RefPointer<dp::TextureManager> mng)
provider.InitStream(0 /*stream index*/, GetBindingInfo(), dp::StackVoidRef(buffer.data()));
m_parts[MY_POSITION_ACCURACY].first = batcher.InsertTriangleFan(state, dp::MakeStackRefPointer(&provider));
ASSERT(m_parts[MY_POSITION_ACCURACY].first.IsValid(), ());
}
}
@ -199,7 +200,9 @@ void MyPosition::CachePointPosition(dp::RefPointer<dp::TextureManager> mng)
m_parts[MY_POSITION_POINT].second = m_nodes.size();
m_parts[MY_POSITION_ARROW].second = m_nodes.size();
m_parts[MY_POSITION_POINT].first = batcher.InsertTriangleStrip(state, dp::MakeStackRefPointer(&pointProvider));
ASSERT(m_parts[MY_POSITION_POINT].first.IsValid(), ());
m_parts[MY_POSITION_ARROW].first = batcher.InsertTriangleStrip(state, dp::MakeStackRefPointer(&arrowProvider));
ASSERT(m_parts[MY_POSITION_ARROW].first.IsValid(), ());
}
}