From 1bb50fccacd1abdd3a501b486c45504bb481ade4 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 16 Jan 2019 18:21:58 -0400 Subject: [PATCH] Reduce peak memory usage when a font's glyph atlas needs to be recreated. --- src/modules/graphics/Font.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/Font.cpp b/src/modules/graphics/Font.cpp index 08e94a28f..6d111b0e4 100644 --- a/src/modules/graphics/Font.cpp +++ b/src/modules/graphics/Font.cpp @@ -152,12 +152,14 @@ void Font::createTexture() image = gfx->newImage(TEXTURE_2D, pixelFormat, size.width, size.height, 1, settings); image->setFilter(filter); - // Initialize the texture with transparent black. - size_t bpp = getPixelFormatSize(pixelFormat); - std::vector emptydata(size.width * size.height * bpp, 0); + { + // Initialize the texture with transparent black. + size_t bpp = getPixelFormatSize(pixelFormat); + std::vector emptydata(size.width * size.height * bpp, 0); - Rect rect = {0, 0, size.width, size.height}; - image->replacePixels(emptydata.data(), emptydata.size(), 0, 0, rect, false); + Rect rect = {0, 0, size.width, size.height}; + image->replacePixels(emptydata.data(), emptydata.size(), 0, 0, rect, false); + } images.emplace_back(image, Acquire::NORETAIN);