From 7817d2169bfd8f21be326d4963dcadee792d5bab Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 11 May 2020 23:54:57 +0100 Subject: [PATCH] Bug fix: SurfaceVector/OsdVector: reference counts for style VectorHandles SurfaceVector::drawText() would only call getStyleRef(DrawStyle) once per string drawn. This resulted in a ref count of 1 regardless of how many chars were drawn. Each time Boxx:draw() was called, surface->fillblt would call removeCommands which dereferenced 1 for each character. This eventually results in ref counts of zero or negative. The GC deletes the DrawStyle/VectorHandle mapping if the ref count is exactly zero, meaning just sometimes a style is deleted when it is to be used. When this happens text on screen disappears. This *might* also be the fix for a Windows client crashing bug. --- surfacevector.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/surfacevector.cc b/surfacevector.cc index 397273a..8f5216f 100644 --- a/surfacevector.cc +++ b/surfacevector.cc @@ -70,7 +70,7 @@ int SurfaceVector::drawText(const char* text, int x, int y, int width, const Dra command_mutex.lock(); - VectorHandle ref = osd->getStyleRef(c); + VectorHandle ref; float* charwidtharray = osd->getCharWidthArray(); int commands_size = commands.size(); int chars = 0; @@ -84,6 +84,7 @@ int SurfaceVector::drawText(const char* text, int x, int y, int width, const Dra while (num_bytes != ((size_t) -1) && num_bytes != ((size_t) -2) && length > 0) { + ref = osd->getStyleRef(c); // Need to call this each time to have OSD get the ref count right. Maybe expose incRefCount sometime SVGCommand::PaintGlyph(commands[commands_size + chars], x + shift, y, tempo, ref); chars++; @@ -111,6 +112,7 @@ int SurfaceVector::drawText(const char* text, int x, int y, int width, const Dra for (int i = 0; i < real_length; i++) { + ref = osd->getStyleRef(c); // Need to call this each time to have OSD get the ref count right. Maybe expose incRefCount sometime SVGCommand::PaintGlyph(commands[commands_size + chars], x + shift, y, temptext[i], ref); chars++; -- 2.39.2