diff --git a/src/ui/windows/chat_tab.cpp b/src/ui/windows/chat_tab.cpp index b04ae8b..7e26819 100644 --- a/src/ui/windows/chat_tab.cpp +++ b/src/ui/windows/chat_tab.cpp @@ -1653,7 +1653,10 @@ void RenderChatTab(App* app) if (cbhov) { ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - ImGui::SetClipboardText(m.body.substr(a, b2 - a).c_str()); + // Offsets can outlive a thread change (an older message inserted above shifts + // indices): never let substr throw std::out_of_range from the render loop. + if (a >= 0 && static_cast(a) <= m.body.size()) + ImGui::SetClipboardText(m.body.substr(a, b2 - a).c_str()); anyMsgClicked = true; } }