From 4b2e3e67266ae4ed153ccbf98b2e5b94de85353b Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Fri, 3 Feb 2023 18:49:13 +0000 Subject: [PATCH] TINYGL: Use realloc to increase the size of the vertex array --- graphics/tinygl/memory.cpp | 4 ++++ graphics/tinygl/vertex.cpp | 4 +--- graphics/tinygl/zbuffer.h | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/graphics/tinygl/memory.cpp b/graphics/tinygl/memory.cpp index d756e39103c..280d90070da 100644 --- a/graphics/tinygl/memory.cpp +++ b/graphics/tinygl/memory.cpp @@ -45,4 +45,8 @@ void *gl_zalloc(int size) { return calloc(1, size); } +void *gl_realloc(void *p, int size) { + return realloc(p, size); +} + } // end of namespace TinyGL diff --git a/graphics/tinygl/vertex.cpp b/graphics/tinygl/vertex.cpp index db70b1bbd85..fa99885e6ea 100644 --- a/graphics/tinygl/vertex.cpp +++ b/graphics/tinygl/vertex.cpp @@ -209,12 +209,10 @@ void GLContext::glopVertex(GLParam *p) { if (n >= vertex_max) { GLVertex *newarray; vertex_max <<= 1; // just double size - newarray = (GLVertex *)gl_malloc(sizeof(GLVertex) * vertex_max); + newarray = (GLVertex *)gl_realloc(vertex, sizeof(GLVertex) * vertex_max); if (!newarray) { error("unable to allocate GLVertex array."); } - memcpy(newarray, vertex, n * sizeof(GLVertex)); - gl_free(vertex); vertex = newarray; } // new vertex entry diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h index ea325b9a803..797062d24b0 100644 --- a/graphics/tinygl/zbuffer.h +++ b/graphics/tinygl/zbuffer.h @@ -742,6 +742,7 @@ private: void gl_free(void *p); void *gl_malloc(int size); void *gl_zalloc(int size); +void *gl_realloc(void *p, int size); } // end of namespace TinyGL