Browse Source

Fix print coloring bug with empty strings (fixes #1171)

Bart van Strien 9 years ago
parent
commit
b328049517
2 changed files with 6 additions and 0 deletions
  1. 1 0
      changes.txt
  2. 5 0
      src/modules/graphics/opengl/Font.cpp

+ 1 - 0
changes.txt

@@ -17,6 +17,7 @@ Released: N/A
   * Fixed love.window.setMode crashing when called with a Canvas active.
   * Fixed gamma correction of ImageFonts and BMFonts with colored images.
   * Fixed the default shader improperly applying gamma correction to per-vertex colors when gamma correction is requested but not supported on OpenGL ES.
+  * Fixed text coloring breaking because of an empty string.
 
   * Improved performance of Channel methods by roughly 2x in many cases.
   

+ 5 - 0
src/modules/graphics/opengl/Font.cpp

@@ -387,6 +387,11 @@ void Font::getCodepointsFromString(const std::vector<ColoredString> &strs, Color
 
 	for (const ColoredString &cstr : strs)
 	{
+		// No need to add the color if the string is empty anyway, and the code
+		// further on assumes no two colors share the same starting position.
+		if (cstr.str.size() == 0)
+			continue;
+
 		IndexedColor c = {cstr.color, (int) codepoints.cps.size()};
 		codepoints.colors.push_back(c);