-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent a segfault when updating ComponentInspector #1167
Prevent a segfault when updating ComponentInspector #1167
Conversation
- Modify the loop in ComponentInspector::Update that removes unused components from the list - The loop iterator may be invalidated by the erase operation in the loop body - this can segfault on macOS (b-tree rebalance fails) - This approach first builds a list of items to remove, then removes them in a second step Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM. Just waiting for CI to finish
- Satisfy include-what-you-use code check Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Thanks @chapulina. I've fixed a missing include needed by code check. The PR needs to be updated with the branch - how do you prefer this to be done: merge (using the github button) or rebase and force push. I'm used to the ardupilot workflow where they do the latter but will run with whatever the OSRF house rules are. |
I think we usually use the github button, because rebase can be disruptive for people's local clones in case they're testing this PR. But often rebasing is ok if no one else is actively reviewing the PR. I'll just click the github button for expediency now. |
Codecov Report
@@ Coverage Diff @@
## ign-gazebo6 #1167 +/- ##
===============================================
- Coverage 62.16% 62.15% -0.01%
===============================================
Files 256 256
Lines 20395 20398 +3
===============================================
Hits 12679 12679
- Misses 7716 7719 +3
Continue to review full report at Codecov.
|
* [macOS] Prevent a segfault when updating ComponentInspector - Modify the loop in ComponentInspector::Update that removes unused components from the list - The loop iterator may be invalidated by the erase operation in the loop body - this can segfault on macOS (b-tree rebalance fails) - This approach first builds a list of items to remove, then removes them in a second step Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com> Co-authored-by: Louise Poubel <louise@openrobotics.org> Signed-off-by: William Lew <WilliamMilesLew@gmail.com>
🦟 Bug fix
Summary
This PR fixes a segfault observed on macOS that occurs when selecting different object types in the EntityTree.
The issue arises in the method
ComponentInspector::Update
in the loop that removes unused components from the component list. The loop iterator may be invalidated by the erase operation in the loop body - this can cause a segfault (the b-tree rebalance fails insidestd::map
). The error was observed on macOS, it may be dependent on the implementation of thestd
libraries.Reproduce the error
Open an ignition gazebo session:
(NB: on macOS the server and gui must be started in different terminals because the approach to forking used in the ignition ruby script is not supported).
Load the component inspector and entity tree (if not already configured)
Select a different component type in the entry tree (eg. select a light if a shape is already selected)
At this point the application may segfault.
Fix
The approach taken is to first build a list of items to remove, then remove them in a second step. This ensures that at no point can a loop iterator be invalidated. There are other approaches that involve using a second iterator in the loop over the component items, however it was found that these may also fail because the erase step is called using a
QMetaObject::invokeMethod
(so the problem may be a threading / mutex issue rather than a invalid iterator). Either way, ensuring that the object being iterated over at the removal step is not the container having items removed prevents this problem.Checklist
codecheck
passed (See contributing)Not all tests pass on macOS (the environment is still experimental). However the failures do not appear to be connected to this change:
97% tests passed, 5 tests failed out of 196 Total Test time (real) = 499.63 sec The following tests FAILED: 47 - UNIT_ModelCommandAPI_TEST (SEGFAULT) 91 - INTEGRATION_examples_build (Failed) 117 - INTEGRATION_level_manager_runtime_performers (Subprocess aborted) 131 - INTEGRATION_multiple_servers (Subprocess aborted) 165 - INTEGRATION_user_commands (SEGFAULT)
Note to maintainers: Remember to use Squash-Merge