diff --git a/plugins/GSdx/GPURenderer.h b/plugins/GSdx/GPURenderer.h index 4a9884d736..01ea219acc 100644 --- a/plugins/GSdx/GPURenderer.h +++ b/plugins/GSdx/GPURenderer.h @@ -114,11 +114,17 @@ protected: void GrowVertexBuffer() { - if(m_vertices != NULL) _aligned_free(m_vertices); + int maxcount = std::max(m_maxcount * 3 / 2, 10000); + Vertex* vertices = (Vertex*)_aligned_malloc(sizeof(Vertex) * maxcount, 16); - m_maxcount = max(10000, m_maxcount * 3/2); - m_vertices = (Vertex*)_aligned_malloc(sizeof(Vertex) * m_maxcount, 16); - m_maxcount -= 100; + if(m_vertices != NULL) + { + memcpy(vertices, m_vertices, sizeof(Vertex) * m_maxcount); + _aligned_free(m_vertices); + } + + m_vertices = vertices; + m_maxcount = maxcount - 100; } __forceinline Vertex* DrawingKick(int& count) diff --git a/plugins/GSdx/GPUState.cpp b/plugins/GSdx/GPUState.cpp index f023c5020c..9d519929a5 100644 --- a/plugins/GSdx/GPUState.cpp +++ b/plugins/GSdx/GPUState.cpp @@ -706,11 +706,17 @@ void GPUState::Buffer::Reserve(int size) { if(size > maxbytes) { - maxbytes = (maxbytes + size + 1023) & ~1023; + int new_maxbytes = (maxbytes + size + 1023) & ~1023; + uint8* new_buff = (uint8*)_aligned_malloc(new_maxbytes, 16); - if(buff != NULL) _aligned_free(buff); + if(buff != NULL) + { + memcpy(new_buff, buff, maxbytes); + _aligned_free(buff); + } - buff = (uint8*)_aligned_malloc(maxbytes, 16); + maxbytes = new_maxbytes; + buff = new_buff; } } diff --git a/plugins/GSdx/GSRenderer.h b/plugins/GSdx/GSRenderer.h index 975938868b..6e8001780a 100644 --- a/plugins/GSdx/GSRenderer.h +++ b/plugins/GSdx/GSRenderer.h @@ -137,11 +137,17 @@ protected: void GrowVertexBuffer() { - if(m_vertices != NULL) _aligned_free(m_vertices); + int maxcount = std::max(m_maxcount * 3 / 2, 10000); + Vertex* vertices = (Vertex*)_aligned_malloc(sizeof(Vertex) * maxcount, 16); - m_maxcount = std::max(10000, m_maxcount * 3 / 2); - m_vertices = (Vertex*)_aligned_malloc(sizeof(Vertex) * m_maxcount, 32); - m_maxcount -= 100; + if(m_vertices != NULL) + { + memcpy(vertices, m_vertices, sizeof(Vertex) * m_maxcount); + _aligned_free(m_vertices); + } + + m_vertices = vertices; + m_maxcount = maxcount - 100; } // Returns a pointer to the drawing vertex. Can return NULL!