From 5d3f54edb2110da18beb7da7b66651541317e85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 26 Feb 2012 15:22:33 +0100 Subject: [PATCH] Warn and assertion fail when mesh has no vertices/indexes before drawing. --- src/IndexedMesh.cpp | 12 ++++++++++++ src/IndexedMesh.h | 3 +++ src/Mesh.cpp | 7 +++++++ src/Mesh.h | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 4674427a1..240f547db 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -15,7 +15,10 @@ #include "IndexedMesh.h" +#include + using namespace std; +using namespace Corrade::Utility; namespace Magnum { @@ -48,4 +51,13 @@ void IndexedMesh::draw() { glDisableVertexAttribArray(*it); } +void IndexedMesh::finalize() { + if(!_indexCount) { + Error() << "IndexedMesh: the mesh has zero index count!"; + assert(0); + } + + Mesh::finalize(); +} + } diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 9eb984fdc..a55422a10 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -76,6 +76,9 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { */ void draw(); + protected: + void finalize(); + private: Buffer _indexBuffer; GLsizei _indexCount; diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 432372492..1030ad6a7 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -16,9 +16,11 @@ #include "Mesh.h" #include "Buffer.h" +#include #include using namespace std; +using namespace Corrade::Utility; namespace Magnum { @@ -68,6 +70,11 @@ void Mesh::finalize() { /* Already finalized */ if(finalized) return; + if(!_vertexCount) { + Error() << "Mesh: the mesh has zero vertex count!"; + assert(0); + } + /* Finalize attribute positions for every buffer */ for(map > >::iterator it = _buffers.begin(); it != _buffers.end(); ++it) { /* Avoid confustion */ diff --git a/src/Mesh.h b/src/Mesh.h index e97e0e7b4..5a2c83dc4 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -214,7 +214,7 @@ class MAGNUM_EXPORT Mesh { * Computes location and stride of each attribute in its buffer. After * this function is called, no new attribute can be bound. */ - void finalize(); + virtual void finalize(); /** * @brief Set the mesh dirty