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

The problem of deconstruction order for Class VisualizationFrame. Wild pointers cause the program to crash #1683

Closed
Luwenyong opened this issue Nov 24, 2021 · 5 comments

Comments

@Luwenyong
Copy link

Luwenyong commented Nov 24, 2021

I developed a panel plug-in using rviz. The plug-in uses the interface during initialization and creates the corresponding ogre:: scenenode.
When I deconstruct my plug-in, I need to destroy the corresponding model node. use sceneManager in vis_manager_ interface destroySceneNode.

But when I close rviz, the core dump will be generated in rviz.
Segmentation fault (core dumped)

I checked the source code of rviz. If modify code here, it could be solve.
rviz\src\rviz\src\rviz\visualization_frame.cpp
(https://github.com/ros-visualization/rviz/blob/melodic-devel/src/rviz/visualization_frame.cpp)

  VisualizationFrame::~VisualizationFrame()
  {
      for (int i = 0; i < custom_panels_.size(); i++)
      {
          delete custom_panels_[i].dock;
      }
      delete render_panel_;
      render_panel_ = nullptr;
      delete manager_;
      manager_ = nullptr;
      //for (int i = 0; i < custom_panels_.size(); i++)
      //{
      //  delete custom_panels_[i].dock;
      //}
  
      delete panel_factory_;
      panel_factory_ = nullptr;
  }

If there is any better way to fix it, maybe we could have a discuss here.

Environment
OS Version: Ubuntu 18.04
ROS Distro: Melodic
RViz, Qt, OGRE, OpenGl version as printed by rviz:

[ INFO] [1637744810.930629000]: rviz version 1.13.18
[ INFO] [1637744810.930694100]: compiled against Qt version 5.9.5
[ INFO] [1637744810.930725100]: compiled against OGRE version 1.9.0 (Ghadamon)
[ INFO] [1637744810.933829600]: Forcing OpenGl version 0.
[ INFO] [1637744811.026552200]: Stereo is NOT SUPPORTED
[ INFO] [1637744811.026656000]: OpenGL device: llvmpipe (LLVM 10.0.0, 256 bits)
[ INFO] [1637744811.026704200]: OpenGl version: 3.1 (GLSL 1.4).
@rhaschke
Copy link
Contributor

Did you analyze the backtrace of your segfault? Is it accessing the already deleted scene graph? Could you provide a link to your source or - even better - a minimal toy example demonstrating the segfault?
Deleting the panels before the render panel seems to be reasonable. I'm not yet sure though, why the current implementation doesn't pose issues in general.

@Luwenyong
Copy link
Author

Luwenyong commented Nov 29, 2021

My plug-in is written like this:

class NodeManager : rviz::Panel
{
public:
...
NodeManager();
~NodeManager();
void onInitialize() override;
...
private:
...
Ogre::SceneManager *sceneManager { nullptr };
Ogre::SceneNode *node { nullptr };
}

void NodeManager::onInitialize()
{
...
const string resource("./model.dae");
rviz::loadMeshFromResource(resource);
sceneManager = vis_manager_->getSceneManager();
Ogre::Entity *entity = sceneManager->createEntity(resource);
Ogre::SceneNode *root = sceneManager->getRootSceneNode();
node = root->createChildSceneNode();
node->attachObject(entity);
node->setVisible(true);
...
}

NodeManager::~NodeManager()
{
...
if (sceneManager != nullptr) {
sceneManager->destroySceneNode(node); // Segmentation fault (core dumped), when I close rviz, the core dump will
// be generated.

}
...
}

@Luwenyong
Copy link
Author

Dear, rhaschke
If you have time, please pay more attention to this question. Thank you very much.

@rhaschke
Copy link
Contributor

I'm waiting for you to provide a compiling minimal code example. Also, I asked for a backtrace. Thanks.

@rhaschke
Copy link
Contributor

Hopefully fixed via b0b5c34.

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