Skip to content

Commit 5fad8b0

Browse files
srmainwaringarjo129
authored andcommitted
NetworkManager: fix entity creation in network secondary (gazebosim#3160)
Fixes gazebosim#3158 ## Summary This fixes a bug which prevents the simulation server running in multiple processes as described in https://gazebosim.org/api/sim/10/distributedsimulation.html. The issue is described in gazebosim#3158, essentially the NetworkManagerSecondary does not have the parent model associated with the performer entity. There is also another issue where a dereference of a parent component to obtain the parent entity causes a segmentation fault when running more than one secondary. A check is added to prevent that. There are some other issues with the distributed simulation as well, such as the pause button not having any effect, but that and other issues will not be dealt with in this PR as they do not prevent the example from running. ## Details The example used is levels.sdf. It is run in distributed mode on two secondaries as follows. Terminal 1: secondary 1 ``` gz sim -v4 -s -r --levels --network-role secondary levels.sdf ``` Terminal 2: secondary 2 ``` gz sim -v4 -s -r --levels --network-role secondary levels.sdf ``` Terminal 3: primary ``` gz sim -v4 -s -r --levels --network-role primary --network-secondaries 2 levels.sdf ``` Terminal 4: gui ``` gz sim -v4 -g ``` Before this patch the errors reported in the associated issue occur. After this no errors are reported. Signed-off-by: Rhys Mainwaring <[email protected]> Co-authored-by: Arjo Chakravarty <[email protected]>
1 parent e67b3f9 commit 5fad8b0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/SimulationRunner.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,17 @@ void SimulationRunner::Step(const UpdateInfo &_info)
914914
GZ_PROFILE("SimulationRunner::Step");
915915
this->currentInfo = _info;
916916

917+
// The Run method does not check for entity creation each iteration
918+
// on network secondaries, so check here to ensure that performers
919+
// have parents assigned.
920+
if (this->networkMgr && this->networkMgr->IsSecondary())
921+
{
922+
if (this->createEntities)
923+
{
924+
this->CreateEntities();
925+
}
926+
}
927+
917928
// Process new ECM state information, typically sent from the GUI after
918929
// a change was made to the GUI's ECM.
919930
this->ProcessNewWorldControlState();

src/network/NetworkManagerSecondary.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ void NetworkManagerSecondary::OnStep(
130130
{
131131
auto parent =
132132
this->dataPtr->ecm->Component<components::ParentEntity>(entityId);
133-
this->dataPtr->ecm->RequestRemoveEntity(parent->Data());
133+
if (parent != nullptr)
134+
{
135+
this->dataPtr->ecm->RequestRemoveEntity(parent->Data());
136+
}
134137

135138
if (this->performers.find(entityId) != this->performers.end())
136139
{

0 commit comments

Comments
 (0)