Skip to content

fix(physics): resolve memory leaks in CharacterControllerTest#572

Merged
Miou-zora merged 1 commit into
mainfrom
565-fix-fix-memory-leaks-in-charactercontrollertest
Apr 7, 2026
Merged

fix(physics): resolve memory leaks in CharacterControllerTest#572
Miou-zora merged 1 commit into
mainfrom
565-fix-fix-memory-leaks-in-charactercontrollertest

Conversation

@Miou-zora

@Miou-zora Miou-zora commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Description

Resolve memory leaks in CharacterControllerTest

Related Issues (Put "None" if there are no related issues)

close #565

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Changes Made

List the main changes in this PR:

  • Called Shutdown systems

Testing

Describe the tests you ran to verify your changes. Please delete options that are not relevant.

  • Unit tests pass (xmake test)
  • Manual testing performed (describe what you tested): run xmake check_leaks -v CharacterControllerTest

Test Environment

  • OS: macOS
  • Compiler: Clang

Screenshots/Videos (Put "None" if there are no related issues)

None

Documentation

Please delete options that are not relevant.

  • No documentation changes are required

Checklist (Don't delete any options)

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Breaking Changes (Put "None" if there are no related issues)

None

Additional Notes (Put "None" if there are no related issues)

None

Summary by CodeRabbit

  • Tests
    • Enhanced character controller test reliability by refining system initialization and shutdown procedures.

@Miou-zora Miou-zora linked an issue Apr 7, 2026 that may be closed by this pull request
@Miou-zora Miou-zora self-assigned this Apr 7, 2026
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Updated the CharacterControllerTest to fix memory leaks by setting the scheduler error handling policy to Nothing and explicitly running the shutdown scheduler after verifying CharacterControllerInternal validity, ensuring proper resource cleanup.

Changes

Cohort / File(s) Summary
CharacterController Test Cleanup
src/plugin/physics/tests/CharacterControllerTest.cpp
Added scheduler error policy configuration and shutdown scheduler invocation to clean up resources and fix memory leaks in the test suite.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • #570: Adds a physics Shutdown system that is executed by the shutdown scheduler invoked in this test fix.

Suggested labels

test

Poem

🐰 A test once leaked with careless grace,
But now the scheduler cleans the place,
With shutdown calls to mend each seam,
Memory flows pure like a rabbit's dream! 🌿✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(physics): resolve memory leaks in CharacterControllerTest' directly describes the main change - fixing memory leaks in the CharacterControllerTest by calling shutdown on systems.
Linked Issues check ✅ Passed The PR fulfills issue #565 by explicitly setting scheduler error handling policy and invoking shutdown scheduler, eliminating memory leaks as verified by unit tests and manual leak checks.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing memory leaks in CharacterControllerTest; no unrelated modifications were introduced.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 565-fix-fix-memory-leaks-in-charactercontrollertest

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

sonarqubecloud Bot commented Apr 7, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/plugin/physics/tests/CharacterControllerTest.cpp (1)

41-46: Make shutdown unconditional even on fatal assertions.

Because ASSERT_TRUE at Line 41 can return early, Line 46 may be skipped. Wrap shutdown in a local guard so cleanup always runs.

♻️ Proposed refactor
 TEST(CharacterControllerPlugin, CharacterControllerCreation)
 {
     Engine::Core core;
+    struct ShutdownGuard {
+        Engine::Core &core;
+        ~ShutdownGuard() { core.GetScheduler<Engine::Scheduler::Shutdown>().RunSystems(); }
+    } shutdownGuard{core};
 
     core.SetErrorPolicyForAllSchedulers(Engine::Scheduler::SchedulerErrorPolicy::Nothing);
@@
     const auto &internal = player.GetComponents<Physics::Component::CharacterControllerInternal>();
     EXPECT_TRUE(internal.IsValid());
-
-    core.GetScheduler<Engine::Scheduler::Shutdown>().RunSystems();
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/plugin/physics/tests/CharacterControllerTest.cpp` around lines 41 - 46,
The test currently calls
ASSERT_TRUE(player.HasComponents<Physics::Component::CharacterControllerInternal>())
which may abort the test early and skip cleanup; wrap the shutdown call
core.GetScheduler<Engine::Scheduler::Shutdown>().RunSystems() in a local RAII
guard so it always runs (e.g., define a small local struct or use a scope-exit
helper whose destructor calls
core.GetScheduler<Engine::Scheduler::Shutdown>().RunSystems()), construct that
guard before the ASSERT_TRUE, then leave the rest of the test using
player.GetComponents<Physics::Component::CharacterControllerInternal>() as-is so
cleanup always executes even on fatal assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/plugin/physics/tests/CharacterControllerTest.cpp`:
- Around line 41-46: The test currently calls
ASSERT_TRUE(player.HasComponents<Physics::Component::CharacterControllerInternal>())
which may abort the test early and skip cleanup; wrap the shutdown call
core.GetScheduler<Engine::Scheduler::Shutdown>().RunSystems() in a local RAII
guard so it always runs (e.g., define a small local struct or use a scope-exit
helper whose destructor calls
core.GetScheduler<Engine::Scheduler::Shutdown>().RunSystems()), construct that
guard before the ASSERT_TRUE, then leave the rest of the test using
player.GetComponents<Physics::Component::CharacterControllerInternal>() as-is so
cleanup always executes even on fatal assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 68dabc2c-2bca-40cb-806f-53a260305e87

📥 Commits

Reviewing files that changed from the base of the PR and between 902f78f and 73bd482.

📒 Files selected for processing (1)
  • src/plugin/physics/tests/CharacterControllerTest.cpp

@Miou-zora Miou-zora merged commit 7df789c into main Apr 7, 2026
38 checks passed
@Miou-zora Miou-zora deleted the 565-fix-fix-memory-leaks-in-charactercontrollertest branch April 7, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FIX] Fix memory leaks in CharacterControllerTest

1 participant