Fixes memory leaks due to not releasing font images properly.
This commit is contained in:
parent
5f65b43f7a
commit
4e42b6c659
14
src/nanovg.c
14
src/nanovg.c
@ -396,6 +396,7 @@ void nvgEndFrame(NVGcontext* ctx)
|
||||
ctx->params.renderFlush(ctx->params.userPtr);
|
||||
if (ctx->fontImageIdx != 0) {
|
||||
int fontImage = ctx->fontImages[ctx->fontImageIdx];
|
||||
ctx->fontImages[ctx->fontImageIdx] = 0;
|
||||
int i, j, iw, ih;
|
||||
// delete images that smaller than current one
|
||||
if (fontImage == 0)
|
||||
@ -404,20 +405,19 @@ void nvgEndFrame(NVGcontext* ctx)
|
||||
for (i = j = 0; i < ctx->fontImageIdx; i++) {
|
||||
if (ctx->fontImages[i] != 0) {
|
||||
int nw, nh;
|
||||
nvgImageSize(ctx, ctx->fontImages[i], &nw, &nh);
|
||||
int image = ctx->fontImages[i];
|
||||
ctx->fontImages[i] = 0;
|
||||
nvgImageSize(ctx, image, &nw, &nh);
|
||||
if (nw < iw || nh < ih)
|
||||
nvgDeleteImage(ctx, ctx->fontImages[i]);
|
||||
nvgDeleteImage(ctx, image);
|
||||
else
|
||||
ctx->fontImages[j++] = ctx->fontImages[i];
|
||||
ctx->fontImages[j++] = image;
|
||||
}
|
||||
}
|
||||
// make current font image to first
|
||||
ctx->fontImages[j++] = ctx->fontImages[0];
|
||||
ctx->fontImages[j] = ctx->fontImages[0];
|
||||
ctx->fontImages[0] = fontImage;
|
||||
ctx->fontImageIdx = 0;
|
||||
// clear all images after j
|
||||
for (i = j; i < NVG_MAX_FONTIMAGES; i++)
|
||||
ctx->fontImages[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user