From 3755603b36550338bb171c0262f8465744acf556 Mon Sep 17 00:00:00 2001 From: Takahito Tejima Date: Tue, 3 Sep 2013 15:13:00 -0700 Subject: [PATCH] Fix error handling in OsdUtilMeshBatch when failed to create vertex buffers. --- opensubdiv/osdutil/batch.h | 42 +++++++++++++++++++++++++++++------- opensubdiv/osdutil/batchCL.h | 29 ++++++++++++++++++++----- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/opensubdiv/osdutil/batch.h b/opensubdiv/osdutil/batch.h index 473fd060..b59c7ce6 100644 --- a/opensubdiv/osdutil/batch.h +++ b/opensubdiv/osdutil/batch.h @@ -365,13 +365,21 @@ OsdUtilMeshBatch::initialize(Co FarPatchTables const * patchTables = farMultiMesh->GetPatchTables(); - _vertexBuffer = numVertexElements ? VertexBuffer::Create(numVertexElements, Base::GetNumVertices()) : NULL; - _varyingBuffer = numVaryingElements ? VertexBuffer::Create(numVaryingElements, Base::GetNumVertices()) : NULL; + if (numVertexElements) { + _vertexBuffer = VertexBuffer::Create(numVertexElements, Base::GetNumVertices()); + if (not _vertexBuffer) return false; + } + + if (numVaryingElements) { + _varyingBuffer = VertexBuffer::Create(numVaryingElements, Base::GetNumVertices()); + if (not _varyingBuffer) return false; + } _drawContext = DrawContext::Create(patchTables, requireFVarData); + if (not _drawContext) return false; - _drawContext->UpdateVertexTexture(_vertexBuffer); + if (_vertexBuffer) _drawContext->UpdateVertexTexture(_vertexBuffer); return true; } @@ -388,13 +396,21 @@ OsdUtilMeshBatch::initialize(Fa Base::initialize(entries, numVertices, numPtexFaces, numVertexElements, batchIndex); - _vertexBuffer = numVertexElements ? VertexBuffer::Create(numVertexElements, numVertices) : NULL; - _varyingBuffer = numVaryingElements ? VertexBuffer::Create(numVaryingElements, numVertices) : NULL; + if (numVertexElements) { + _vertexBuffer = VertexBuffer::Create(numVertexElements, numVertices); + if (not _vertexBuffer) return false; + } + + if (numVaryingElements) { + _varyingBuffer = VertexBuffer::Create(numVaryingElements, numVertices); + if (not _varyingBuffer) return false; + } _drawContext = DrawContext::Create(patchTables, requireFVarData); + if (not _drawContext) return false; - _drawContext->UpdateVertexTexture(_vertexBuffer); + if (_vertexBuffer) _drawContext->UpdateVertexTexture(_vertexBuffer); return true; } @@ -429,7 +445,12 @@ OsdUtilMeshBatch::Create(Comput OsdUtilMeshBatch *batch = new OsdUtilMeshBatch(); - batch->initialize(computeController, entries, farMultiMesh, numVertexElements, numVaryingElements, batchIndex, requireFVarData); + if (not batch->initialize(computeController, entries, farMultiMesh, + numVertexElements, numVaryingElements, + batchIndex, requireFVarData)) { + delete batch; + batch = NULL; + } delete farMultiMesh; @@ -450,7 +471,12 @@ OsdUtilMeshBatch::Create(FarPat OsdUtilMeshBatch *batch = new OsdUtilMeshBatch(); - batch->initialize(patchTables, entries, numVertices, numPtexFaces, numVertexElements, numVaryingElements, batchIndex, requireFVarData); + if (not batch->initialize(patchTables, entries, numVertices, numPtexFaces, + numVertexElements, numVaryingElements, + batchIndex, requireFVarData)) { + delete batch; + batch = NULL; + } return batch; } diff --git a/opensubdiv/osdutil/batchCL.h b/opensubdiv/osdutil/batchCL.h index 05880fb7..0b6ed169 100644 --- a/opensubdiv/osdutil/batchCL.h +++ b/opensubdiv/osdutil/batchCL.h @@ -161,8 +161,15 @@ OsdUtilMeshBatch::initializ FarPatchTables const * patchTables = farMultiMesh->GetPatchTables(); - _vertexBuffer = numVertexElements ? VertexBuffer::Create(numVertexElements, Base::GetNumVertices(), _computeController->GetContext()) : NULL; - _varyingBuffer = numVaryingElements ? VertexBuffer::Create(numVaryingElements, Base::GetNumVertices(), _computeController->GetContext()) : NULL; + if (numVertexElements) { + _vertexBuffer = VertexBuffer::Create(numVertexElements, Base::GetNumVertices(), _computeController->GetContext()); + if (not _vertexBuffer) return false; + } + + if (numVaryingElements) { + _varyingBuffer = VertexBuffer::Create(numVaryingElements, Base::GetNumVertices(), _computeController->GetContext()); + if (not _varyingBuffer) return false; + } _drawContext = DrawContext::Create(patchTables, requireFVarData); @@ -183,8 +190,15 @@ OsdUtilMeshBatch::initializ bool requireFVarData) { Base::initialize(numVertices, numPtexFaces, numVertexElements, batchIndex); - _vertexBuffer = numVertexElements ? VertexBuffer::Create(numVertexElements, Base::GetNumVertices(), _computeController->GetContext()) : NULL; - _varyingBuffer = numVaryingElements ? VertexBuffer::Create(numVaryingElements, Base::GetNumVertices(), _computeController->GetContext()) : NULL; + if (numVertexElements) { + _vertexBuffer = VertexBuffer::Create(numVertexElements, Base::GetNumVertices(), _computeController->GetContext()); + if (not _vertexBuffer) return false; + } + + if (numVaryingElements) { + _varyingBuffer = VertexBuffer::Create(numVaryingElements, Base::GetNumVertices(), _computeController->GetContext()); + if (not _varyingBuffer) return false; + } _drawContext = DrawContext::Create(patchTables, requireFVarData); @@ -225,7 +239,12 @@ OsdUtilMeshBatch::Create(Co OsdUtilMeshBatch *batch = new OsdUtilMeshBatch(); - batch->initialize(computeController, entries, farMultiMesh, numVertexElements, numVaryingElements, batchIndex, requireFVarData); + if (not batch->initialize(computeController, entries, farMultiMesh, + numVertexElements, numVaryingElements, + batchIndex, requireFVarData)) { + delete batch; + batch = NULL; + } delete farMultiMesh;