From d6457e9983b7ea6021e15e3b52a57c022d9255cd Mon Sep 17 00:00:00 2001 From: "sudonim1@gmail.com" Date: Sat, 25 Jan 2014 19:14:28 +0000 Subject: [PATCH] GSDX: Fixed the allocation checks in the previous couple of revs. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5832 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GPURenderer.h | 10 ++++++---- plugins/GSdx/GSState.cpp | 14 ++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/GSdx/GPURenderer.h b/plugins/GSdx/GPURenderer.h index 43919a5a01..6ab0e54721 100644 --- a/plugins/GSdx/GPURenderer.h +++ b/plugins/GSdx/GPURenderer.h @@ -123,15 +123,17 @@ protected: int maxcount = std::max(m_maxcount * 3 / 2, 10000); Vertex* vertices = (Vertex*)_aligned_malloc(sizeof(Vertex) * maxcount, 32); + if (!vertices) + { + printf("GSdx: failed to allocate %d bytes for verticles.\n", sizeof(Vertex) * maxcount); + throw GSDXError(); + } + if (m_vertices != NULL && vertices != NULL) { memcpy(vertices, m_vertices, sizeof(Vertex) * m_maxcount); _aligned_free(m_vertices); } - else // very bad! - { - printf("GSdx: failed to allocate %d bytes for verticles.\n", sizeof(Vertex) * maxcount); - } m_vertices = vertices; m_maxcount = maxcount - 100; diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index 7e83cc2817..309d49e3ff 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -2300,16 +2300,18 @@ void GSState::GrowVertexBuffer() GSVertex* vertex = (GSVertex*)_aligned_malloc(sizeof(GSVertex) * maxcount, 32); uint32* index = (uint32*)_aligned_malloc(sizeof(uint32) * maxcount * 3, 32); // worst case is slightly less than vertex number * 3 + if (!vertex || !index) + { + printf("GSdx: failed to allocate %d bytes for verticles and %d for indices.\n", sizeof(GSVertex) * maxcount, sizeof(uint32) * maxcount * 3); + throw GSDXError(); + } + if (m_vertex.buff != NULL && vertex != NULL) { memcpy(vertex, m_vertex.buff, sizeof(GSVertex) * m_vertex.tail); _aligned_free(m_vertex.buff); } - else // very bad! - { - printf("GSdx: failed to allocate %d bytes for verticles.\n", sizeof(GSVertex) * maxcount); - } if (m_index.buff != NULL && index != NULL) { @@ -2317,10 +2319,6 @@ void GSState::GrowVertexBuffer() _aligned_free(m_index.buff); } - else // very bad! - { - printf("GSdx: failed to allocate %d bytes for indices.\n", sizeof(uint32) * maxcount * 3); - } m_vertex.buff = vertex; m_vertex.maxcount = maxcount - 3; // -3 to have some space at the end of the buffer before DrawingKick can grow it