From d8c5d663ef7d35e8a79efa27ccff2cdca4124cb7 Mon Sep 17 00:00:00 2001 From: harrand Date: Tue, 27 Feb 2024 01:55:55 +0000 Subject: [PATCH] [text_renderer] fixed a nasty gpu crash (device lost) which was caused whenever the internal string buffer got resized coz it needs more space. the new string_locators in the expanded buffer did not have their memory zero'd, causing them to have indeterminate values and causing the compute shader to iterate over them and read garbage memory (and then go on to read out of bounds which causes a device-lost) --- src/tz/ren/text.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tz/ren/text.cpp b/src/tz/ren/text.cpp index 9ace992602..bc1b94d376 100644 --- a/src/tz/ren/text.cpp +++ b/src/tz/ren/text.cpp @@ -317,6 +317,9 @@ namespace tz::ren { return; } + std::vector new_empties; + new_empties.resize(string_count - old_cap); + std::span new_empties_span = new_empties; tz::gl::get_device().get_renderer(rh).edit( tz::gl::RendererEditBuilder{} .buffer_resize @@ -324,6 +327,12 @@ namespace tz::ren .buffer_handle = this->string_buffer, .size = string_count * sizeof(string_locator) }) + .write + ({ + .resource = this->string_buffer, + .data = std::as_bytes(new_empties_span), + .offset = old_cap * sizeof(string_locator), + }) .build() ); tz::gl::get_device().get_renderer(ch).edit(