diff --git a/util/gpu/web/hb-gpu-web-webgpu.cc b/util/gpu/web/hb-gpu-web-webgpu.cc index 0e1884dd4..1f4026340 100644 --- a/util/gpu/web/hb-gpu-web-webgpu.cc +++ b/util/gpu/web/hb-gpu-web-webgpu.cc @@ -289,10 +289,16 @@ static const char *arg_font = nullptr; static void rebuild_buffer (const char *text) { - /* strdup first -- text may alias current_text. */ - char *new_text = strdup (text); - free (current_text); - current_text = new_text; + if (!text) + text = default_text_en; + + if (text != current_text) + { + /* strdup first -- text may alias current_text. */ + char *new_text = strdup (text); + free (current_text); + current_text = new_text; + } demo_font_clear_cache (current_demo_font); atlas_clear_cb (&atlas); @@ -300,7 +306,8 @@ rebuild_buffer (const char *text) demo_buffer_clear (buffer); demo_point_t top_left = {0, 0}; demo_buffer_move_to (buffer, &top_left); - demo_buffer_add_text (buffer, text, current_demo_font, 1); + if (current_text) + demo_buffer_add_text (buffer, current_text, current_demo_font, 1); atlas.dirty = true; demo_view_reset (vu); diff --git a/util/gpu/web/hb-gpu-web.cc b/util/gpu/web/hb-gpu-web.cc index a362bf8f2..43599d8cf 100644 --- a/util/gpu/web/hb-gpu-web.cc +++ b/util/gpu/web/hb-gpu-web.cc @@ -68,10 +68,16 @@ static bool custom_text; static void rebuild_buffer (const char *text) { - /* strdup first -- text may alias current_text. */ - char *new_text = strdup (text); - free (current_text); - current_text = new_text; + if (!text) + text = default_text_en; + + if (text != current_text) + { + /* strdup first -- text may alias current_text. */ + char *new_text = strdup (text); + free (current_text); + current_text = new_text; + } demo_font_clear_cache (current_demo_font); demo_atlas_clear (renderer->get_atlas ()); @@ -79,7 +85,8 @@ rebuild_buffer (const char *text) demo_buffer_clear (buffer); demo_point_t top_left = {0, 0}; demo_buffer_move_to (buffer, &top_left); - demo_buffer_add_text (buffer, text, current_demo_font, 1); + if (current_text) + demo_buffer_add_text (buffer, current_text, current_demo_font, 1); demo_view_reset (vu); /* Don't call demo_view_display here: it may run from a * microtask (e.g. the font-fetch .then() callback) where the