From 35049b7a535ce94db3bc7ad1c9e863713cd370b1 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 27 May 2014 23:23:24 +0200 Subject: [PATCH] Throw exception if extracted region is too large. --- examples/Paging/main.cpp | 10 ++++++---- .../include/PolyVoxCore/CubicSurfaceExtractor.inl | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 3700c632..ee2d2d23 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -186,13 +186,15 @@ int main(int argc, char *argv[]) std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl; //Extract the surface - auto mesh = extractCubicMesh(&volData, reg); + auto mesh = extractCubicMesh(&volData, reg2); std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl; - //Pass the surface to the OpenGL window - openGLWidget.addMesh(mesh); + auto decodedMesh = decode(mesh); - openGLWidget.setViewableRegion(reg); + //Pass the surface to the OpenGL window + openGLWidget.addMesh(decodedMesh); + + openGLWidget.setViewableRegion(reg2); //Run the message pump. return app.exec(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index b152f90c..da7803cd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -45,6 +45,12 @@ namespace PolyVox ,m_tBorderValue(tBorderValue) { m_funcIsQuadNeededCallback = isQuadNeeded; + + // This extractor has a limit as to how large the extracted region can be, because the vertex positions are encoded with a single byte per component. + int32_t maxReionDimension = 256; + POLYVOX_THROW_IF(region.getWidthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions"); + POLYVOX_THROW_IF(region.getHeightInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions"); + POLYVOX_THROW_IF(region.getDepthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions"); } template