From 78746c89729b21a9d112c2a034e0b9c55772a2c4 Mon Sep 17 00:00:00 2001 From: Miha Lunar Date: Thu, 25 Sep 2014 13:23:51 +0200 Subject: [PATCH] Merged fixed allocation for paths from nanovg --- examples/common/nanovg/nanovg_bgfx.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/common/nanovg/nanovg_bgfx.cpp b/examples/common/nanovg/nanovg_bgfx.cpp index c367eebe..c0629f2f 100644 --- a/examples/common/nanovg/nanovg_bgfx.cpp +++ b/examples/common/nanovg/nanovg_bgfx.cpp @@ -763,10 +763,13 @@ namespace static int glnvg__allocPaths(struct GLNVGcontext* gl, int n) { int ret = 0; - if (gl->npaths+n > gl->cpaths) - { - gl->cpaths = gl->cpaths == 0 ? glnvg__maxi(n, 32) : gl->cpaths * 2; - gl->paths = (struct GLNVGpath*)realloc(gl->paths, sizeof(struct GLNVGpath) * gl->cpaths); + if (gl->npaths + n > gl->cpaths) { + GLNVGpath* paths; + int cpaths = glnvg__maxi(gl->npaths + n, 128) + gl->cpaths / 2; // 1.5x Overallocate + paths = (GLNVGpath*)realloc(gl->paths, sizeof(GLNVGpath) * cpaths); + if (paths == NULL) return -1; + gl->paths = paths; + gl->cpaths = cpaths; } ret = gl->npaths; gl->npaths += n;