Browse Source

Reduce peak memory usage when a font's glyph atlas needs to be recreated.

Alex Szpakowski 6 years ago
parent
commit
1bb50fccac
1 changed files with 7 additions and 5 deletions
  1. 7 5
      src/modules/graphics/Font.cpp

+ 7 - 5
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<uint8> emptydata(size.width * size.height * bpp, 0);
+	{
+		// Initialize the texture with transparent black.
+		size_t bpp = getPixelFormatSize(pixelFormat);
+		std::vector<uint8> 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);