From bb94cff886a7379a89a997d307093169b5b757c9 Mon Sep 17 00:00:00 2001 From: Gamer64 Date: Fri, 26 Dec 2025 02:55:52 +0100 Subject: [PATCH] [chore] Fixed a couple memory leaks using up ~15 MB each iteration (#398) Co-authored-by: Jarrod Norwell Co-authored-by: Gamer64 <76565986+Gamer64ytb@users.noreply.github.com> Co-authored-by: Caio Oliveira Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/398 Reviewed-by: Caio Oliveira Reviewed-by: Lizzie Co-authored-by: Gamer64 Co-committed-by: Gamer64 --- src/android/app/build.gradle.kts | 1 - src/android/gradle.properties | 2 ++ src/common/announce_multiplayer_room.h | 8 +++---- src/core/frontend/applets/cabinet.h | 2 +- src/core/frontend/applets/software_keyboard.h | 23 +++++++++++-------- src/core/hle/service/nfc/nfc_types.h | 5 +++- src/core/hle/service/nfp/nfp_types.h | 5 +++- .../service/ns/platform_service_manager.cpp | 4 ++-- src/frontend_common/play_time_manager.h | 2 +- .../helpers/joycon_protocol/poller.cpp | 3 +++ src/network/room_member.h | 5 +++- src/video_core/control/scheduler.cpp | 5 +++- .../renderer_vulkan/vk_rasterizer.cpp | 4 ++-- src/yuzu/configuration/configure_input.h | 11 +++++---- .../configure_input_player_widget.cpp | 11 +++++---- .../configure_input_player_widget.h | 5 +++- src/yuzu/main_window.cpp | 4 ++-- src/yuzu/main_window.h | 12 +++++----- src/yuzu/multiplayer/lobby_p.h | 5 +++- 19 files changed, 74 insertions(+), 43 deletions(-) diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts index 18529242f5..61e817e546 100644 --- a/src/android/app/build.gradle.kts +++ b/src/android/app/build.gradle.kts @@ -39,7 +39,6 @@ android { buildFeatures { viewBinding = true - buildConfig = true } compileOptions { diff --git a/src/android/gradle.properties b/src/android/gradle.properties index 1da29b6797..151f7378d6 100644 --- a/src/android/gradle.properties +++ b/src/android/gradle.properties @@ -14,6 +14,8 @@ android.useAndroidX=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official kotlin.parallel.tasks.in.project=true +android.defaults.buildfeatures.buildconfig=true + # Android Gradle plugin 8.0.2 android.suppressUnsupportedCompileSdk=34 android.native.buildOutput=verbose \ No newline at end of file diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h index bbc1dd8a3b..bca0ee8e2e 100644 --- a/src/common/announce_multiplayer_room.h +++ b/src/common/announce_multiplayer_room.h @@ -34,8 +34,8 @@ struct Member { struct RoomInformation { std::string name; ///< Name of the server std::string description; ///< Server description - u32 member_slots; ///< Maximum number of members in this room - u16 port; ///< The port of this room + u32 member_slots{}; ///< Maximum number of members in this room + u16 port{}; ///< The port of this room GameInfo preferred_game; ///< Game to advertise that you want to play std::string host_username; ///< Forum username of the host }; @@ -46,8 +46,8 @@ struct Room { std::string id; std::string verify_uid; ///< UID used for verification std::string ip; - u32 net_version; - bool has_password; + u32 net_version{}; + bool has_password = false; std::vector members; }; diff --git a/src/core/frontend/applets/cabinet.h b/src/core/frontend/applets/cabinet.h index 157bfe38c6..9cf1126397 100644 --- a/src/core/frontend/applets/cabinet.h +++ b/src/core/frontend/applets/cabinet.h @@ -21,7 +21,7 @@ namespace Core::Frontend { struct CabinetParameters { Service::NFP::TagInfo tag_info; Service::NFP::RegisterInfo register_info; - Service::NFP::CabinetMode mode; + Service::NFP::CabinetMode mode{}; }; using CabinetCallback = std::function; diff --git a/src/core/frontend/applets/software_keyboard.h b/src/core/frontend/applets/software_keyboard.h index a32a98e4cf..5e82a2acba 100644 --- a/src/core/frontend/applets/software_keyboard.h +++ b/src/core/frontend/applets/software_keyboard.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -20,9 +23,9 @@ struct KeyboardInitializeParameters { std::u16string initial_text; char16_t left_optional_symbol_key; char16_t right_optional_symbol_key; - u32 max_text_length; - u32 min_text_length; - s32 initial_cursor_position; + u32 max_text_length{}; + u32 min_text_length{}; + s32 initial_cursor_position{}; Service::AM::Frontend::SwkbdType type; Service::AM::Frontend::SwkbdPasswordMode password_mode; Service::AM::Frontend::SwkbdTextDrawType text_draw_type; @@ -34,12 +37,12 @@ struct KeyboardInitializeParameters { }; struct InlineAppearParameters { - u32 max_text_length; - u32 min_text_length; - f32 key_top_scale_x; - f32 key_top_scale_y; - f32 key_top_translate_x; - f32 key_top_translate_y; + u32 max_text_length{}; + u32 min_text_length{}; + f32 key_top_scale_x{}; + f32 key_top_scale_y{}; + f32 key_top_translate_x{}; + f32 key_top_translate_y{}; Service::AM::Frontend::SwkbdType type; Service::AM::Frontend::SwkbdKeyDisableFlags key_disable_flags; bool key_top_as_floating; @@ -50,7 +53,7 @@ struct InlineAppearParameters { struct InlineTextParameters { std::u16string input_text; - s32 cursor_position; + s32 cursor_position{}; }; class SoftwareKeyboardApplet : public Applet { diff --git a/src/core/hle/service/nfc/nfc_types.h b/src/core/hle/service/nfc/nfc_types.h index 68e724442f..6d44014ea1 100644 --- a/src/core/hle/service/nfc/nfc_types.h +++ b/src/core/hle/service/nfc/nfc_types.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later @@ -79,7 +82,7 @@ using DeviceHandle = u64; // This is nn::nfc::TagInfo struct TagInfo { - UniqueSerialNumber uuid; + UniqueSerialNumber uuid{}; u8 uuid_length; INSERT_PADDING_BYTES(0x15); NfcProtocol protocol; diff --git a/src/core/hle/service/nfp/nfp_types.h b/src/core/hle/service/nfp/nfp_types.h index 2505eb551d..8330134d18 100644 --- a/src/core/hle/service/nfp/nfp_types.h +++ b/src/core/hle/service/nfp/nfp_types.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later @@ -315,7 +318,7 @@ static_assert(sizeof(ModelInfo) == 0x40, "ModelInfo is an invalid size"); // This is nn::nfp::RegisterInfo struct RegisterInfo { Service::Mii::CharInfo mii_char_info; - WriteDate creation_date; + WriteDate creation_date{}; AmiiboName amiibo_name; u8 font_region; INSERT_PADDING_BYTES(0x7A); diff --git a/src/core/hle/service/ns/platform_service_manager.cpp b/src/core/hle/service/ns/platform_service_manager.cpp index 8468661b20..293c014eae 100644 --- a/src/core/hle/service/ns/platform_service_manager.cpp +++ b/src/core/hle/service/ns/platform_service_manager.cpp @@ -164,7 +164,7 @@ IPlatformServiceManager::IPlatformServiceManager(Core::System& system_, const ch // Rebuild shared fonts from data ncas or synthesize impl->shared_font = std::make_shared(SHARED_FONT_MEM_SIZE); - for (auto font : SHARED_FONTS) { + for (auto& font : SHARED_FONTS) { FileSys::VirtualFile romfs; const auto nca = nand->GetEntry(static_cast(font.first), FileSys::ContentRecordType::Data); @@ -261,7 +261,7 @@ Result IPlatformServiceManager::GetSharedFontInOrderOfPriority( out_font_sizes.size(), impl->shared_font_regions.size()}); for (size_t i = 0; i < max_size; i++) { - auto region = impl->GetSharedFontRegion(i); + auto& region = impl->GetSharedFontRegion(i); out_font_codes[i] = static_cast(i); out_font_offsets[i] = region.offset; diff --git a/src/frontend_common/play_time_manager.h b/src/frontend_common/play_time_manager.h index a99ccebb1e..ea5ddb637b 100644 --- a/src/frontend_common/play_time_manager.h +++ b/src/frontend_common/play_time_manager.h @@ -48,7 +48,7 @@ private: void Save(); PlayTimeDatabase database; - u64 running_program_id; + u64 running_program_id{}; std::jthread play_time_thread; }; diff --git a/src/input_common/helpers/joycon_protocol/poller.cpp b/src/input_common/helpers/joycon_protocol/poller.cpp index 1aab9e12a3..abb0216473 100644 --- a/src/input_common/helpers/joycon_protocol/poller.cpp +++ b/src/input_common/helpers/joycon_protocol/poller.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later diff --git a/src/network/room_member.h b/src/network/room_member.h index 37e9ea16a5..8cc59adecc 100644 --- a/src/network/room_member.h +++ b/src/network/room_member.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -53,7 +56,7 @@ struct ChatEntry { /// Represents a system status message. struct StatusMessageEntry { - StatusMessageTypes type; ///< Type of the message + StatusMessageTypes type{}; ///< Type of the message /// Subject of the message. i.e. the user who is joining/leaving/being banned, etc. std::string nickname; std::string username; diff --git a/src/video_core/control/scheduler.cpp b/src/video_core/control/scheduler.cpp index f7cbe204ee..441466beb2 100644 --- a/src/video_core/control/scheduler.cpp +++ b/src/video_core/control/scheduler.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later @@ -17,7 +20,7 @@ void Scheduler::Push(s32 channel, CommandList&& entries) { std::unique_lock lk(scheduling_guard); auto it = channels.find(channel); ASSERT(it != channels.end()); - auto channel_state = it->second; + auto& channel_state = it->second; gpu.BindChannel(channel_state->bind_id); channel_state->dma_pusher->Push(std::move(entries)); channel_state->dma_pusher->DispatchCalls(); diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 687663dd6d..7d91f21aa6 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -108,7 +108,7 @@ VkViewport GetViewportState(const Device& device, const Maxwell& regs, size_t in VkRect2D GetScissorState(const Maxwell& regs, size_t index, u32 up_scale = 1, u32 down_shift = 0) { const auto& src = regs.scissor_test[index]; - VkRect2D scissor; + VkRect2D scissor{}; const auto scale_up = [&](s32 value) -> s32 { if (value == 0) { return 0U; @@ -374,7 +374,7 @@ void RasterizerVulkan::Clear(u32 layer_count) { } UpdateViewportsState(regs); - VkRect2D default_scissor; + VkRect2D default_scissor{}; default_scissor.offset.x = 0; default_scissor.offset.y = 0; default_scissor.extent.width = (std::numeric_limits::max)(); diff --git a/src/yuzu/configuration/configure_input.h b/src/yuzu/configuration/configure_input.h index beb503dae0..9bdd0d68ca 100644 --- a/src/yuzu/configuration/configure_input.h +++ b/src/yuzu/configuration/configure_input.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: 2016 Citra Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -71,11 +74,11 @@ private: std::unique_ptr profiles; - std::array player_controllers; - std::array player_tabs; + std::array player_controllers{}; + std::array player_tabs{}; // Checkboxes representing the "Connected Controllers". - std::array connected_controller_checkboxes; - ConfigureInputAdvanced* advanced; + std::array connected_controller_checkboxes{}; + ConfigureInputAdvanced* advanced = nullptr; Core::System& system; }; diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index 5c7eb59d7c..3228b5f17f 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -689,10 +692,10 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen { // Draw joysticks using namespace Settings::NativeAnalog; - const auto l_stick = QPointF(stick_values[LStick].x.value, stick_values[LStick].y.value); - const auto l_button = button_values[Settings::NativeButton::LStick]; - const auto r_stick = QPointF(stick_values[RStick].x.value, stick_values[RStick].y.value); - const auto r_button = button_values[Settings::NativeButton::RStick]; + const auto& l_stick = QPointF(stick_values[LStick].x.value, stick_values[LStick].y.value); + const auto& l_button = button_values[Settings::NativeButton::LStick]; + const auto& r_stick = QPointF(stick_values[RStick].x.value, stick_values[RStick].y.value); + const auto& r_button = button_values[Settings::NativeButton::RStick]; DrawJoystick(p, center + QPointF(-171, -41) + (l_stick * 4), 1.0f, l_button); DrawJoystick(p, center + QPointF(171, 8) + (r_stick * 4), 1.0f, r_button); diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h index 76340912d3..d7ec943240 100644 --- a/src/yuzu/configuration/configure_input_player_widget.h +++ b/src/yuzu/configuration/configure_input_player_widget.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -214,7 +217,7 @@ private: bool mapping_active{}; int blink_counter{}; - int callback_key; + int callback_key{}; QColor button_color{}; ColorMapping colors{}; Core::HID::LedPattern led_pattern{0, 0, 0, 0}; diff --git a/src/yuzu/main_window.cpp b/src/yuzu/main_window.cpp index 585752ad89..ed3d0f8466 100644 --- a/src/yuzu/main_window.cpp +++ b/src/yuzu/main_window.cpp @@ -1495,7 +1495,7 @@ void MainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { (state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { auto_paused = true; OnPauseGame(); - } else if (!emu_thread->IsRunning() && auto_paused && state == Qt::ApplicationActive) { + } else if (!emu_thread->IsRunning() && auto_paused && (state & Qt::ApplicationActive)) { auto_paused = false; OnStartGame(); } @@ -1505,7 +1505,7 @@ void MainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { (state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { Settings::values.audio_muted = true; auto_muted = true; - } else if (auto_muted && state == Qt::ApplicationActive) { + } else if (auto_muted && (state & Qt::ApplicationActive)) { Settings::values.audio_muted = false; auto_muted = false; } diff --git a/src/yuzu/main_window.h b/src/yuzu/main_window.h index bbd76e847f..754fc67c06 100644 --- a/src/yuzu/main_window.h +++ b/src/yuzu/main_window.h @@ -482,13 +482,13 @@ private: MultiplayerState* multiplayer_state = nullptr; - GRenderWindow* render_window; - GameList* game_list; - LoadingScreen* loading_screen; + GRenderWindow* render_window = nullptr; + GameList* game_list = nullptr; + LoadingScreen* loading_screen = nullptr; QTimer shutdown_timer; OverlayDialog* shutdown_dialog{}; - GameListPlaceholder* game_list_placeholder; + GameListPlaceholder* game_list_placeholder = nullptr; std::vector vk_device_records; @@ -531,7 +531,7 @@ private: QString startup_icon_theme; // Debugger panes - ControllerDialog* controller_dialog; + ControllerDialog* controller_dialog = nullptr; QAction* actions_recent_files[max_recent_files_item]; @@ -543,7 +543,7 @@ private: QTranslator translator; // Install progress dialog - QProgressDialog* install_progress; + QProgressDialog* install_progress = nullptr; // Last game booted, used for multi-process apps QString last_filename_booted; diff --git a/src/yuzu/multiplayer/lobby_p.h b/src/yuzu/multiplayer/lobby_p.h index 77ec1fcde1..d4ef62c9e6 100644 --- a/src/yuzu/multiplayer/lobby_p.h +++ b/src/yuzu/multiplayer/lobby_p.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -175,7 +178,7 @@ public: private: QString username; QString nickname; - u64 title_id; + u64 title_id{}; QString game_name; };