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

Run server and client in the same process #793

Open
wants to merge 49 commits into
base: main
Choose a base branch
from

Conversation

ahcorde
Copy link
Contributor

@ahcorde ahcorde commented Apr 27, 2021

Signed-off-by: ahcorde [email protected]

🎉 New feature

Summary

Related to this issue #556

Test it

ign gazebo -r -v 4 --same-process shapes.sdf
ign gazebo -r -v 4 --same-process camera_sensor.sdf  # -> crash

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

@ahcorde ahcorde requested review from iche033 and chapulina April 27, 2021 10:49
@github-actions github-actions bot added the 🏯 fortress Ignition Fortress label Apr 27, 2021
@ahcorde ahcorde marked this pull request as draft April 27, 2021 10:49
@ahcorde ahcorde self-assigned this Apr 27, 2021
@ahcorde
Copy link
Contributor Author

ahcorde commented Apr 27, 2021

I made a comment in the related issue #556 (comment)

I want to make it work then I will clean up te code.

chapulina and others added 4 commits May 12, 2021 14:08
@ahcorde ahcorde changed the base branch from main to chapulina/6/scene_manager June 2, 2021 15:27
@ahcorde ahcorde force-pushed the ahcorde/same_process branch from 476a11a to ae902c3 Compare June 2, 2021 15:28
@ahcorde
Copy link
Contributor Author

ahcorde commented Jun 2, 2021

I updated the base PR to match with the recent refactoring in the scene3D.

Current status

  • Gui and sensor thread shared the same scene.
    • not able to visualize the objects in the scene 3D
    • When I try to load the ImageDisplay then I get a crash
  • Ogre crashes when we try to use the wheel to zoom in and zoom out. In particular in the method OgreRayQuery::ClosestPoint. The vertex from the meshes are not fetched properly.
  • Ogre2 crashes on start in the method void Ogre2RenderTarget::Render() in the call engine->OgreRoot()->renderOneFrame();

to reproduce:

/home/ahcorde/ignition_fortress_leak/install/bin/ign gazebo --gui-config src/ign-gazebo/src/gui/gui.config camera_sensor.sdf -v 4 --same_process --render-engine ogre --render-engine-gui ogre --render-engine-server ogre

If you want to try Ogre two, you should modify the gui.config file and replace ogre with ogre2

/home/ahcorde/ignition_fortress_leak/install/bin/ign gazebo --gui-config src/ign-gazebo/src/gui/gui.config camera_sensor.sdf -v 4 --same_process --render-engine ogre2 --render-engine-gui ogre2 --render-engine-server ogre2

Limitations

everything should run with ogre or ogre2 but we cannot mix both renders when gui and server are running in the same process.

ahcorde added 4 commits June 3, 2021 22:09
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
@ahcorde
Copy link
Contributor Author

ahcorde commented Jun 4, 2021

I have two issues right now:

  • Sometimes ign-gazebo starts with some repeated entities in the Entity tree

Selección_102

  • When the entity is removed from the entity tree, it removed from the scene but not from the entity tree

same_process_remove_entity

ahcorde added 2 commits June 8, 2021 10:16
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
@ahcorde
Copy link
Contributor Author

ahcorde commented Jun 8, 2021

Decisions that I have made

There are two differences main way to launch ign-gazebo: with sensors and without sensors. This have some implications.

When we are runninig with sensors

There are two RenderUtils available: One in the sensor system plugin and another in the GUI. This is the easiest case because there are two system plugins that remove entities: Sensors and Physics which runs at the same speed. But the Scene 3D is running just at 30Hz. This may cause some issues in the Entity tree plugin. Some of the EachRemoved cycles are lost. I have created some events to be able to remove/add entities in the Entity tree plugin, this event are emitted in the renderutils class.

  • RemoveFromECM
  • AddToECM

The GzSceneManager should not update renderutil because the sensor thread will do it.

When running without sensors

In this case the physics system plugin will be the only one with access to the removeEach calls. In this case this plugin will send an event called UpdateGUIECM to avoid missing any removals.

There is another event called EnableSensors this event is used GzSceneManager. In this case the sensor system plugin is not updating the RenderUtils because it not running, so this event allow us to check if we should update the Scene 3D from the Gui system plugin.

  • EnableSensors
  • UpdateGUIECM

Render

On of the limitiation that we have, it is that we can only update the render scene in the same thread, otherwise we will get a crash. When running in the same process there are two Renderutils trying to update the scene3d in different threads, it's important to load in the first time the Scene3D to set the option useCurrentGLContext to 1. For this reason we need to create a event called Render, this event is emitted in the GzSceneManager plugin every time that an event Render is received in the eventFilter method.


Notes

@ahcorde ahcorde marked this pull request as ready for review June 8, 2021 10:30
@ahcorde ahcorde requested a review from azeey as a code owner June 8, 2021 10:30
@ahcorde
Copy link
Contributor Author

ahcorde commented Jun 8, 2021

@iche033
Copy link
Contributor

iche033 commented Jun 9, 2021

With the latest changes, the events for keeping GUI plugins in sync with server side seems to be working from testing.

I also want to brainstorm ideas on how we could reuse more of the current ECM infrastructure. I think the problem all came down to the GuiRunner running the gui plugins at 30 Hz in a separate thread. What do you think of the following proposal:

The idea above is so that the gui plugins can keep using the EachRemoved call without having to connect to new events. This reduces the effort required to port other gui plugins (or user's own custom gui plugins) to work in the same process mode.

@ahcorde ahcorde requested a review from chapulina August 13, 2021 09:56
if (this->entityItems.find(_entity) != this->entityItems.end())
{
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Broke this off into #974

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

I took a look at the sensors - 3D scene synchronization, and it concerns me that we're instantiating 2 RenderUtil classes that compete to create and update entities. I'm also wondering what impact the GUI running the render loop will have on the sensors' update rate. See more detailed comments below.

@@ -316,6 +331,45 @@ void SensorsPrivate::Run()
this->renderThread = std::thread(&SensorsPrivate::RenderThread, this);
}

//////////////////////////////////////////////////
void SensorsPrivate::Render()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function ever called?

return rendering::VisualPtr();
auto vis = this->dataPtr->scene->VisualByName(name);
this->dataPtr->visuals[_id] = vis;
return vis;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these changes here because Sensors and Scene3D are trying to create the same entity? I think we should solve the underlying issue instead of protecting against it.

Right now I see lots of error messages:

$ ign gazebo sensors_demo.sdf --same-process                                                                                                          
[GUI] [Err] [SceneManager.cc:187] Visual: [ground_plane] already exists                                                                     
[GUI] [Err] [SceneManager.cc:187] Visual: [box] already exists                                                                              
[GUI] [Err] [SceneManager.cc:187] Visual: [cameras_alone] already exists                                                                    
[GUI] [Err] [SceneManager.cc:187] Visual: [camera_with_lidar] already exists                                                                
[GUI] [Err] [SceneManager.cc:187] Visual: [rgbd_camera] already exists                                                                      
[GUI] [Err] [SceneManager.cc:187] Visual: [thermal_camera] already exists                                                                   
[GUI] [Err] [SceneManager.cc:187] Visual: [Construction Cone] already exists                                                                
[GUI] [Err] [SceneManager.cc:1054] Visual: [sun::sunVisual] already exists                                                                  
[GUI] [Err] [SceneManager.cc:267] Entity with Id: [36] already exists in the scene                                                          
[GUI] [Err] [SceneManager.cc:1098] Light with Id: [38] already exists in the scene                                                          
[GUI] [Err] [SceneManager.cc:1054] Visual: [sun::sunVisual] already exists

We need to have a single authority on who's managing the lifecycle of entities in the scene when we run sensors and GUI in the same process. Otherwise, they're both trying to do duplicate work, which may eventually cause undefined behaviour.

My suggestion is that during sameProcess, we should have a single RenderUtil and SceneManager instantiated, instead of 2 trying to update the same scene.

if (!this->sameProcess)
{
IGN_PROFILE("Update");
this->renderUtil.Update();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you comment on the reasoning for having the GUI drive the render loop? Sensors are pickier about update rates, so I think they should have control.

@chapulina chapulina added the beta Targeting beta release of upcoming collection label Sep 8, 2021
@chapulina chapulina removed the beta Targeting beta release of upcoming collection label Sep 22, 2021
@chapulina
Copy link
Contributor

Didn't make it into beta, can come in a minor release.

@chapulina chapulina added 🌱 garden Ignition Garden and removed 🏯 fortress Ignition Fortress labels Nov 16, 2021
@adlarkin adlarkin removed their request for review December 6, 2021 18:13
@chapulina chapulina added the enhancement New feature or request label Jul 25, 2022
@chapulina chapulina removed the 🌱 garden Ignition Garden label Aug 6, 2022
@azeey azeey added beta Targeting beta release of upcoming collection and removed beta Targeting beta release of upcoming collection labels Jul 31, 2023
@azeey azeey added beta Targeting beta release of upcoming collection and removed beta Targeting beta release of upcoming collection labels Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

7 participants