From bfadd2539beae7542eb7e708a695d482a7f180b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 27 Apr 2026 20:55:46 +0200 Subject: [PATCH] Some code hardening in TextEdit view --- Common/UI/View.cpp | 5 +++++ SDL/SDLMain.cpp | 2 +- UI/DeveloperToolsScreen.cpp | 9 ++++----- UI/DeveloperToolsScreen.h | 1 - 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index d3945af4c1..aa606ddf73 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -1311,6 +1311,10 @@ void TextEdit::Draw(UIContext &dc) { } selectAtX_ = -1; } + if (caret_ < 0 || caret_ > text_.size()) { + ERROR_LOG(Log::UI, "Caret position out of bounds: %d (text length %d)", caret_, (int)text_.size()); + caret_ = (int)text_.size(); + } dc.PopScissor(); } @@ -1501,6 +1505,7 @@ bool TextEdit::Key(const KeyInput &input) { } void TextEdit::InsertAtCaret(const char *text) { + _dbg_assert_(caret_ >= 0 && caret_ <= (int)text_.size()); size_t len = strlen(text); for (size_t i = 0; i < len; i++) { text_.insert(text_.begin() + caret_, text[i]); diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index b218ee48e3..6853525fb7 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -1342,7 +1342,7 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta void UpdateTextFocus() { if (g_textFocusChanged) { - INFO_LOG(Log::System, "Updating text focus: %d", g_textFocus); + DEBUG_LOG(Log::System, "Updating text focus: %d", g_textFocus); if (g_textFocus) { SDL_StartTextInput(); } else { diff --git a/UI/DeveloperToolsScreen.cpp b/UI/DeveloperToolsScreen.cpp index 7bb25526b9..9118f55202 100644 --- a/UI/DeveloperToolsScreen.cpp +++ b/UI/DeveloperToolsScreen.cpp @@ -242,7 +242,10 @@ void DeveloperToolsScreen::CreateTestsTab(UI::LinearLayout *list) { using namespace UI; auto dev = GetI18NCategory(I18NCat::DEVELOPER); - list->Add(new Choice(dev->T("Touchscreen Test")))->OnClick.Handle(this, &DeveloperToolsScreen::OnTouchscreenTest); + list->Add(new Choice(dev->T("Touchscreen Test")))->OnClick.Add([this](UI::EventParams &e) { + screenManager()->push(new TouchTestScreen(gamePath_)); + // Handle touchscreen test event + }); // list->Add(new Choice(dev->T("Memstick Test")))->OnClick.Handle(this, &DeveloperToolsScreen::OnMemstickTest); Choice *frameDumpTests = list->Add(new Choice(dev->T("Framedump tests"))); frameDumpTests->OnClick.Add([this](UI::EventParams &e) { @@ -705,10 +708,6 @@ void DeveloperToolsScreen::OnGPUDriverTest(UI::EventParams &e) { screenManager()->push(new GPUDriverTestScreen()); } -void DeveloperToolsScreen::OnTouchscreenTest(UI::EventParams &e) { - screenManager()->push(new TouchTestScreen(gamePath_)); -} - void DeveloperToolsScreen::OnJitAffectingSetting(UI::EventParams &e) { System_PostUIMessage(UIMessage::REQUEST_CLEAR_JIT); } diff --git a/UI/DeveloperToolsScreen.h b/UI/DeveloperToolsScreen.h index 8c597c317d..0eb1a025ee 100644 --- a/UI/DeveloperToolsScreen.h +++ b/UI/DeveloperToolsScreen.h @@ -39,7 +39,6 @@ private: void OnMIPSTracerClearTracer(UI::EventParams &e); void OnGPUDriverTest(UI::EventParams &e); void OnMemstickTest(UI::EventParams &e); - void OnTouchscreenTest(UI::EventParams &e); void OnCopyStatesToRoot(UI::EventParams &e); void MemoryMapTest();