From 21490c5228bb61a44c7e0a225d6e95d39fb19889 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 5 Feb 2011 18:19:15 +0000 Subject: [PATCH] Small crash fixes. --- examples/Basic/OpenGLWidget.cpp | 15 +++++++++++++++ library/PolyVoxCore/include/Volume.inl | 9 +++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index 43c27fba..d5a8f283 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -7,6 +7,9 @@ using namespace std; OpenGLWidget::OpenGLWidget(QWidget *parent) :QGLWidget(parent) + ,m_uBeginIndex(0) + ,m_uEndIndex(0) + ,noOfIndices(0) ,m_xRotation(0) ,m_yRotation(0) { @@ -14,6 +17,12 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh) { + if((surfaceMesh.getNoOfIndices() == 0) || (surfaceMesh.getNoOfVertices() == 0)) + { + //We don't have a valid mesh + return; + } + //Convienient access to the vertices and indices const vector& vecIndices = surfaceMesh.getIndices(); const vector& vecVertices = surfaceMesh.getVertices(); @@ -77,6 +86,12 @@ void OpenGLWidget::resizeGL(int w, int h) void OpenGLWidget::paintGL() { + if(noOfIndices == 0) + { + //Nothing to render + return; + } + //Clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/library/PolyVoxCore/include/Volume.inl b/library/PolyVoxCore/include/Volume.inl index d1fd9a4c..d53427fc 100644 --- a/library/PolyVoxCore/include/Volume.inl +++ b/library/PolyVoxCore/include/Volume.inl @@ -51,9 +51,6 @@ namespace PolyVox { //Create a volume of the right size. resize(uWidth, uHeight, uDepth, uBlockSideLength); - - //Create the border block - m_pBorderBlock.fill(VoxelType()); } //////////////////////////////////////////////////////////////////////////////// @@ -327,7 +324,11 @@ namespace PolyVox for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i) { m_pBlocks[i].resize(m_uBlockSideLength); - } + } + + //Create the border block + m_pBorderBlock.resize(uBlockSideLength); + m_pBorderBlock.fill(VoxelType()); //Other properties we might find useful later m_uLongestSideLength = (std::max)((std::max)(m_uWidth,m_uHeight),m_uDepth);