Skip to content

[BUG] Display glitch: sometimes, menu briefly shows "????" when returning via touchscreen #5329

@mcarbonne

Description

@mcarbonne

Printer model

Core One L

Firmware version

6.3.5

Upgrades and modifications

None

Printing from...

N.A.

Describe the bug

When returning from a sub-menu (such as Settings or Control) using the touchscreen, a transient rendering glitch occurs where the returning menu item (such as the "Return" line) is briefly filled with ???? characters. This usually means that a buffer overflow is occurring somewhere.

How to reproduce

When it occurred, I was able to reproduce the bug several times. But I still did not manage to reproduce it since.
I asked AI to investigate and it suggested the following patches :

diff --git a/src/guiapi/src/i_window_menu_item.cpp b/src/guiapi/src/i_window_menu_item.cpp
index bdadab108..6907775a6 100644
--- a/src/guiapi/src/i_window_menu_item.cpp
+++ b/src/guiapi/src/i_window_menu_item.cpp
@@ -49,6 +49,7 @@ IWindowMenuItem::~IWindowMenuItem() {
     if (focused_menu_item == this) {
         focused_menu_item = nullptr;
         focused_menu_item_edited = false;
+        focused_menu_item_roll.Deinit();
     }
 }
 
diff --git a/src/guiapi/src/text_roll.cpp b/src/guiapi/src/text_roll.cpp
index 0f67e4e3e..323ad9d36 100644
--- a/src/guiapi/src/text_roll.cpp
+++ b/src/guiapi/src/text_roll.cpp
@@ -77,6 +77,10 @@ invalidate_t txtroll_t::Tick() {
 void txtroll_t::Init(const Rect16 &rect, const string_view_utf8 &text, Font font, padding_ui8_t padding) {
     hidden_char_cnt = meas(rect, text, font, padding);
     font_w = resource_font(font)->w;
+    draw_progress = 0;
+    px_cd = 0;
+    count = 0;
+    phase_progress = 0;
     phase = phase_t::init_roll;
 }
 

and another (unrelated ?) fix:

diff --git a/src/lang/string_view_utf8.cpp b/src/lang/string_view_utf8.cpp
index a482888f1..3c3a415bb 100644
--- a/src/lang/string_view_utf8.cpp
+++ b/src/lang/string_view_utf8.cpp
@@ -193,7 +193,9 @@ bool StringReaderUtf8::trigger_buffer_switch(uint8_t ch) {
 
 StringReaderUtf8 &StringReaderUtf8::skip(uint16_t num_of_chars) {
     while (num_of_chars--) {
-        getUtf8Char();
+        if (getUtf8Char() == '\0') {
+            break;
+        }
     }
     return *this;
 }
@@ -238,7 +240,9 @@ void StringReaderUtf8::advance() {
 
     switch (view_.type()) {
     case Type::memory_string:
-        view_.memory_ptr++;
+        if (*view_.memory_ptr != '\0') {
+            view_.memory_ptr++;
+        }
         break;
 
     case Type::file_string:
diff --git a/tests/unit/lang/string_view_utf8/tests.cpp b/tests/unit/lang/string_view_utf8/tests.cpp
index 9dda0ca98..fb61d4057 100644
--- a/tests/unit/lang/string_view_utf8/tests.cpp
+++ b/tests/unit/lang/string_view_utf8/tests.cpp
@@ -292,3 +292,16 @@ TEST_CASE("string_view_utf8::string_build", "[string_view_utf8]") {
     REQUIRE_THAT(compare_buff, Equals(ref_text_in_between));
     REQUIRE(copied_bytes == strlen(ref_text_in_between));
 }
+
+TEST_CASE("string_view_utf8::StringReaderUtf8 safety checks", "[string_view_utf8]") {
+    static const uint8_t utf8str[] = "Return";
+    string_view_utf8 sf = string_view_utf8::MakeRAM(utf8str);
+    StringReaderUtf8 reader(sf);
+
+    // Skip way past the end of the string
+    reader.skip(100);
+
+    // Ensure we are stuck at null terminator and it doesn't read garbage
+    REQUIRE(reader.getUtf8Char() == '\0');
+    REQUIRE(reader.getbyte() == '\0');
+}

Also, just before having the bug, I did several calibrations (belt tension, phase stepping, input shaper).

Expected behavior

No response

Files

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions