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

dynamic casting no-sense #13

Open
mhernando opened this issue Jul 30, 2020 · 1 comment
Open

dynamic casting no-sense #13

mhernando opened this issue Jul 30, 2020 · 1 comment

Comments

@mhernando
Copy link

I'm using your code as base of a robot specific plugin. I've realized that you are doing a share_ptr dynamic conversion between BasePtr and ModelPtr. I think you have to avoid that. It generates dangerous memory issues.

I think you sould change:
"""
physics::BasePtr b1 = this->world->ModelByName(model1);

if (b1 == NULL){
  ROS_ERROR_STREAM(model1 << " model was not found");
  return false;
}

ROS_DEBUG_STREAM("Casting into ModelPtr");
physics::ModelPtr m1(dynamic_cast<physics::Model*>(b1.get()));
j.m1 = m1;

"""
Directly to
"""
physics::ModelPtr m1 = this->world->ModelByName(model1);
if(!m1){ROS_ERROR_STREAM(model1 << " model was not found");
return false;
"""

If you do not have a list of attached joints, the pluging would delete the module, because of the BasePtr shared_pointer.

@awesomebytes
Copy link
Collaborator

awesomebytes commented Jul 30, 2020 via email

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

No branches or pull requests

2 participants