Skip to content

Commit 5f3f1cd

Browse files
authored
Merge pull request #207 from cortex-command-community/input-handling-refactor
Fix TextInput use after free during activity
2 parents 66d5f19 + c706eae commit 5f3f1cd

File tree

5 files changed

+193
-188
lines changed

5 files changed

+193
-188
lines changed

Source/GUI/GUITextPanel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,12 @@ void GUITextPanel::Draw(GUIScreen* Screen) {
141141
}
142142

143143
void GUITextPanel::OnGainFocus() {
144+
GUIPanel::OnGainFocus();
144145
m_Manager->GetInputController()->StartTextInput();
145146
}
146147

147148
void GUITextPanel::OnLoseFocus() {
149+
GUIPanel::OnLoseFocus();
148150
m_Manager->GetInputController()->StopTextInput();
149151
}
150152

Source/Main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void PollSDLEvents() {
229229
case SDL_EVENT_JOYSTICK_BUTTON_UP :
230230
case SDL_EVENT_JOYSTICK_ADDED :
231231
case SDL_EVENT_JOYSTICK_REMOVED :
232-
g_UInputMan.QueueInputEvent(sdlEvent);
232+
g_UInputMan.HandleInputEvent(sdlEvent);
233233
break;
234234
default:
235235
break;
@@ -273,6 +273,7 @@ void RunMenuLoop() {
273273
}
274274
g_ConsoleMan.Update();
275275

276+
g_UInputMan.EndFrame();
276277
g_WindowMan.GetScreenBuffer()->Begin();
277278
g_MenuMan.Draw();
278279
g_ConsoleMan.Draw(g_FrameMan.GetBackBuffer32());
@@ -358,6 +359,7 @@ void RunGameLoop() {
358359
g_PresetMan.ClearReloadEntityPresetCalledThisUpdate();
359360

360361
g_PerformanceMan.StopPerformanceMeasurement(PerformanceMan::SimTotal);
362+
g_UInputMan.EndFrame();
361363

362364
if (!g_ActivityMan.IsInActivity()) {
363365
g_TimerMan.PauseSim(true);
@@ -379,6 +381,7 @@ void RunGameLoop() {
379381
g_PerformanceMan.ResetSimUpdateTimer();
380382
updateStartTime = g_TimerMan.GetAbsoluteTime();
381383
}
384+
382385
}
383386

384387
updateEndAndDrawStartTime = g_TimerMan.GetAbsoluteTime();

Source/Managers/ConsoleMan.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ void ConsoleMan::Update() {
295295
}
296296

297297
if (!m_ReadOnly) {
298-
m_InputTextBox->SetEnabled(true);
299-
m_InputTextBox->SetFocus();
298+
if (!m_InputTextBox->GetEnabled() || !m_InputTextBox->HasFocus()) {
299+
m_InputTextBox->SetEnabled(true);
300+
m_InputTextBox->SetFocus();
301+
}
300302

301303
if (!m_InputLog.empty() && !g_UInputMan.FlagCtrlState()) {
302304
if (g_UInputMan.KeyPressed(SDLK_UP)) {

0 commit comments

Comments
 (0)