From 7a3dcda2a2fa42c79fb39660ff7b61f183bb2774 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Thu, 3 Aug 2023 17:26:54 +0800 Subject: [PATCH] FIX: avoid the bug in wxControl::Ellipsize api exist a bug where the last bit of Ellipsize api in the wxwidgets is an out of bounds array with the '&' symbol. Change-Id: Ie54f7958195815bd9b028f86284cc5da582cee8a --- src/slic3r/GUI/PartPlate.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 6d3138d24..156c7a182 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -1778,6 +1778,18 @@ bool PartPlate::generate_plate_name_texture() wxString cur_plate_name = from_u8(m_name); wxGCDC dc; wxString limitTextWidth = wxControl::Ellipsize(cur_plate_name, dc, wxELLIPSIZE_END, bed_width); + if (limitTextWidth.size() ==4 && limitTextWidth.rfind("...") != std::string::npos && cur_plate_name.rfind('&') != std::string::npos) { + // Avoided a bug where the last bit of Ellipsize api in the wxwidgets is an out of bounds array with the '&' symbol + // wxwidgets version:3.2.2.1 + for (auto it = cur_plate_name.rbegin(); it != cur_plate_name.rend(); ++it) { + if (*it == '&') { + cur_plate_name = cur_plate_name.RemoveLast(); + } else { + break; + } + } + limitTextWidth = wxControl::Ellipsize(cur_plate_name, dc, wxELLIPSIZE_END, bed_width); + } if (limitTextWidth.Length()==0) { return false; }