From c627e55451608feedbe366760d2bc35135252125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 13 Sep 2014 21:23:23 -0700 Subject: [PATCH] Fixed issue #149. --- examples/common/nanovg/nanovg_bgfx.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/common/nanovg/nanovg_bgfx.cpp b/examples/common/nanovg/nanovg_bgfx.cpp index 3808da57..c367eebe 100644 --- a/examples/common/nanovg/nanovg_bgfx.cpp +++ b/examples/common/nanovg/nanovg_bgfx.cpp @@ -773,13 +773,17 @@ namespace return ret; } - static int glnvg__allocVerts(struct GLNVGcontext* gl, int n) + static int glnvg__allocVerts(GLNVGcontext* gl, int n) { int ret = 0; if (gl->nverts+n > gl->cverts) { - gl->cverts = gl->cverts == 0 ? glnvg__maxi(n, 256) : gl->cverts * 2; - gl->verts = (struct NVGvertex*)realloc(gl->verts, sizeof(struct NVGvertex) * gl->cverts); + NVGvertex* verts; + int cverts = glnvg__maxi(gl->nverts + n, 4096) + gl->cverts/2; // 1.5x Overallocate + verts = (NVGvertex*)realloc(gl->verts, sizeof(NVGvertex) * cverts); + if (verts == NULL) return -1; + gl->verts = verts; + gl->cverts = cverts; } ret = gl->nverts; gl->nverts += n;