From 206f5936cb28d0d030a9feb9d4fee87029e6b2ae Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 7 Mar 2025 00:58:24 -0500 Subject: [PATCH] Creating render textures is expensive - reuse the same one for all text size calculations. This dramatically speeds up the unit tests that test every dialog. Addresses #678 but not sure if this covers every possible case. --- src/dialogxml/widgets/message.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dialogxml/widgets/message.cpp b/src/dialogxml/widgets/message.cpp index 0695447c..9ba0a09c 100644 --- a/src/dialogxml/widgets/message.cpp +++ b/src/dialogxml/widgets/message.cpp @@ -171,8 +171,9 @@ void cTextMsg::recalcRect() { // Fix the height and calculate the width calc_rect.width() = 100 * max_line_chars; } - sf::RenderTexture temp; - temp.create(calc_rect.width(), calc_rect.height()); + static bool inited = false; + static sf::RenderTexture temp; + if(!inited) inited = temp.create(512, 512); // Let's hope this is big enough for any text we want… rectangle test_rect = calc_rect; test_rect.offset(-test_rect.left, -test_rect.top); rects = draw_string_hilite(temp, test_rect, getText(), style, hilites, sf::Color::Black);