Skip to content
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

Avoid nullptr dereference if TouchPlugin is not attached to a model entity. #2069

Merged
merged 3 commits into from
Aug 4, 2023
Merged

Avoid nullptr dereference if TouchPlugin is not attached to a model entity. #2069

merged 3 commits into from
Aug 4, 2023

Conversation

jrutgeer
Copy link
Contributor

@jrutgeer jrutgeer commented Aug 3, 2023

🦟 Bug fix

Summary

Two small fixes:

  • Avoid nullptr dereference in case the plugin is not attached to a model (as sdfConfig is initialized only if TouchPlugin::Configure() is successful, see code snippet below),
  • Avoid execution of preUpdate() code if the system was not initialized correctly.

I also changed the documentation somewhat to better explain what the plugin actually does.


void TouchPlugin::Configure(const Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
EntityComponentManager &_ecm, EventManager &)
{
this->dataPtr->model = Model(_entity);
if (!this->dataPtr->model.Valid(_ecm))
{
gzerr << "Touch plugin should be attached to a model entity. "
<< "Failed to initialize." << std::endl;
return;
}
this->dataPtr->sdfConfig = _sdf->Clone();
}

… model.

Skip PreUpdate if the configuration was not successful.

Signed-off-by: Johan Rutgeerts <[email protected]>
@jrutgeer jrutgeer requested a review from mjcarroll as a code owner August 3, 2023 12:23
@github-actions github-actions bot added the 🌱 garden Ignition Garden label Aug 3, 2023
Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Good catch. Thanks!

@azeey azeey added the beta Targeting beta release of upcoming collection label Aug 3, 2023
Signed-off-by: Addisu Z. Taddese <[email protected]>
@codecov
Copy link

codecov bot commented Aug 3, 2023

Codecov Report

Merging #2069 (3ee204d) into gz-sim7 (50a99e6) will decrease coverage by 0.13%.
Report is 21 commits behind head on gz-sim7.
The diff coverage is 100.00%.

❗ Current head 3ee204d differs from pull request most recent head 42bf976. Consider uploading reports for the commit 42bf976 to get more accurate results

@@             Coverage Diff             @@
##           gz-sim7    #2069      +/-   ##
===========================================
- Coverage    65.00%   64.88%   -0.13%     
===========================================
  Files          354      354              
  Lines        28667    28688      +21     
===========================================
- Hits         18636    18613      -23     
- Misses       10031    10075      +44     
Files Changed Coverage Δ
include/gz/sim/ServerConfig.hh 100.00% <ø> (ø)
include/gz/sim/rendering/MarkerManager.hh 100.00% <ø> (ø)
src/LevelManager.cc 89.39% <ø> (ø)
src/systems/touch_plugin/TouchPlugin.hh 100.00% <ø> (ø)
src/systems/physics/Physics.cc 67.78% <100.00%> (+0.45%) ⬆️
src/systems/touch_plugin/TouchPlugin.cc 87.40% <100.00%> (ø)

... and 2 files with indirect coverage changes

@azeey
Copy link
Contributor

azeey commented Aug 3, 2023

#2070 seems to have fixed the ABI failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Targeting beta release of upcoming collection 🌱 garden Ignition Garden
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants