fix: Prevent controller crashes and memory leaks in game list grid view

- Fix memory leak in PopulateGridView() and FilterGridView() by properly
  deleting old QStandardItemModel instances before creating new ones
- Add safety checks in controller navigation to prevent crashes when
  accessing uninitialized controller data
- Improve controller input handling to only send events to visible and
  properly initialized views
- Add null pointer checks in SetViewMode() to prevent crashes when
  setting current index on empty models
- Add proper cleanup in GameList destructor to prevent memory leaks
  on application shutdown

The main issue was that switching between list and grid views created
new models without properly cleaning up old ones, leading to memory
leaks. Additionally, controller navigation would send keyboard events
to both views simultaneously, causing crashes when one view was not
properly initialized or visible.

Fixes crashes when using controller navigation in grid view mode.

Thanks to Beta Testers acarajé & Hayate Yoshida (吉田 疾風) for finding the bug.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-07-21 21:23:51 +10:00
parent c7bc05f1d0
commit 0d05f64e79
2 changed files with 58 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2025 Citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/settings_input.h"
@@ -42,6 +43,12 @@ void ControllerNavigation::ControllerUpdateEvent(Core::HID::ControllerTriggerTyp
if (!Settings::values.controller_navigation) {
return;
}
// Safety check: ensure controllers are properly initialized
if (!is_controller_set || !player1_controller || !handheld_controller) {
return;
}
if (type == Core::HID::ControllerTriggerType::Button) {
ControllerUpdateButton();
return;
@@ -54,6 +61,11 @@ void ControllerNavigation::ControllerUpdateEvent(Core::HID::ControllerTriggerTyp
}
void ControllerNavigation::ControllerUpdateButton() {
// Safety check: ensure controllers are properly initialized
if (!is_controller_set || !player1_controller || !handheld_controller) {
return;
}
const auto controller_type = player1_controller->GetNpadStyleIndex();
const auto& player1_buttons = player1_controller->GetButtonsValues();
const auto& handheld_buttons = handheld_controller->GetButtonsValues();
@@ -91,6 +103,11 @@ void ControllerNavigation::ControllerUpdateButton() {
}
void ControllerNavigation::ControllerUpdateStick() {
// Safety check: ensure controllers are properly initialized
if (!is_controller_set || !player1_controller || !handheld_controller) {
return;
}
const auto controller_type = player1_controller->GetNpadStyleIndex();
const auto& player1_sticks = player1_controller->GetSticksValues();
const auto& handheld_sticks = player1_controller->GetSticksValues();