fix(physics): resolve memory leaks in CharacterControllerTest#572
Conversation
📝 WalkthroughWalkthroughUpdated the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/plugin/physics/tests/CharacterControllerTest.cpp (1)
41-46: Make shutdown unconditional even on fatal assertions.Because
ASSERT_TRUEat 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
📒 Files selected for processing (1)
src/plugin/physics/tests/CharacterControllerTest.cpp



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.
Changes Made
List the main changes in this PR:
Testing
Describe the tests you ran to verify your changes. Please delete options that are not relevant.
xmake test)xmake check_leaks -v CharacterControllerTestTest Environment
Screenshots/Videos (Put "None" if there are no related issues)
None
Documentation
Please delete options that are not relevant.
Checklist (Don't delete any options)
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