TINYGL: Use realloc to increase the size of the vertex array
This commit is contained in:
parent
c89cc0bc4c
commit
4b2e3e6726
3 changed files with 6 additions and 3 deletions
|
@ -45,4 +45,8 @@ void *gl_zalloc(int size) {
|
||||||
return calloc(1, size);
|
return calloc(1, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *gl_realloc(void *p, int size) {
|
||||||
|
return realloc(p, size);
|
||||||
|
}
|
||||||
|
|
||||||
} // end of namespace TinyGL
|
} // end of namespace TinyGL
|
||||||
|
|
|
@ -209,12 +209,10 @@ void GLContext::glopVertex(GLParam *p) {
|
||||||
if (n >= vertex_max) {
|
if (n >= vertex_max) {
|
||||||
GLVertex *newarray;
|
GLVertex *newarray;
|
||||||
vertex_max <<= 1; // just double size
|
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) {
|
if (!newarray) {
|
||||||
error("unable to allocate GLVertex array.");
|
error("unable to allocate GLVertex array.");
|
||||||
}
|
}
|
||||||
memcpy(newarray, vertex, n * sizeof(GLVertex));
|
|
||||||
gl_free(vertex);
|
|
||||||
vertex = newarray;
|
vertex = newarray;
|
||||||
}
|
}
|
||||||
// new vertex entry
|
// new vertex entry
|
||||||
|
|
|
@ -742,6 +742,7 @@ private:
|
||||||
void gl_free(void *p);
|
void gl_free(void *p);
|
||||||
void *gl_malloc(int size);
|
void *gl_malloc(int size);
|
||||||
void *gl_zalloc(int size);
|
void *gl_zalloc(int size);
|
||||||
|
void *gl_realloc(void *p, int size);
|
||||||
|
|
||||||
} // end of namespace TinyGL
|
} // end of namespace TinyGL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue