Skip to content

Commit

Permalink
Fix rendering tests (#2086)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Ian Chen <ichen@openrobotics.org>
Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org>
  • Loading branch information
iche033 and azeey authored Aug 31, 2023
1 parent 5846393 commit 197596a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,7 @@ void SceneManager::Clear()
this->dataPtr->actorTrajectories.clear();
this->dataPtr->lights.clear();
this->dataPtr->particleEmitters.clear();
this->dataPtr->projectors.clear();
this->dataPtr->sensors.clear();
this->dataPtr->scene.reset();
this->dataPtr->originalTransparency.clear();
Expand Down
2 changes: 2 additions & 0 deletions src/systems/camera_video_recorder/CameraVideoRecorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ void CameraVideoRecorderPrivate::OnPostRender()
}
}

this->scene.reset();
this->camera.reset();
// reset the event connection to prevent unnecessary render callbacks
this->postRenderConn.reset();
}
Expand Down
27 changes: 10 additions & 17 deletions src/systems/lens_flare/LensFlare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,9 @@ class gz::sim::systems::LensFlarePrivate
/// \brief Name of the camera
public: std::string cameraName;

/// \brief Pointer to the light
public: rendering::LightPtr light;

/// \brief Name of the Light
public: std::string lightName;

/// \brief Pointer to the LensFlarePass
public: rendering::LensFlarePassPtr lensFlarePass;

/// \brief Scale of the lens flare
public: double scale = 1.0;

Expand Down Expand Up @@ -193,10 +187,7 @@ void LensFlarePrivate::OnPostRender()
}

// get light
if (!this->light)
{
this->light = this->scene->LightByIndex(0);
}
auto light = this->scene->LightByIndex(0);

rendering::RenderEngine *engine = this->camera->Scene()->Engine();
rendering::RenderPassSystemPtr rpSystem = engine->RenderPassSystem();
Expand All @@ -212,14 +203,14 @@ void LensFlarePrivate::OnPostRender()
return;
}

this->lensFlarePass =
auto lensFlarePass =
std::dynamic_pointer_cast<rendering::LensFlarePass>(flarePass);
this->lensFlarePass->Init(this->scene);
this->lensFlarePass->SetEnabled(true);
this->lensFlarePass->SetLight(this->light);
this->lensFlarePass->SetScale(this->scale);
this->lensFlarePass->SetColor(this->color);
this->lensFlarePass->SetOcclusionSteps(this->occlusionSteps);
lensFlarePass->Init(this->scene);
lensFlarePass->SetEnabled(true);
lensFlarePass->SetLight(light);
lensFlarePass->SetScale(this->scale);
lensFlarePass->SetColor(this->color);
lensFlarePass->SetOcclusionSteps(this->occlusionSteps);

this->camera->AddRenderPass(lensFlarePass);
gzmsg << "LensFlare Render pass added to the camera" << std::endl;
Expand All @@ -228,6 +219,8 @@ void LensFlarePrivate::OnPostRender()
// disconnect from render event after adding lens flare pass to prevent
// unecessary callbacks;
this->postRenderConn.reset();
this->scene.reset();
this->camera.reset();
}

GZ_ADD_PLUGIN(LensFlare,
Expand Down
1 change: 1 addition & 0 deletions src/systems/sensors/Sensors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ void SensorsPrivate::RenderThread()
for (const auto id : this->sensorIds)
this->sensorManager.Remove(id);

this->scene.reset();
this->renderUtil.Destroy();
gzdbg << "SensorsPrivate::RenderThread stopped" << std::endl;
}
Expand Down
18 changes: 18 additions & 0 deletions src/systems/shader_param/ShaderParam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class gz::sim::systems::ShaderParamPrivate
/// \brief Connection to pre-render event callback
public: gz::common::ConnectionPtr connection{nullptr};

/// \brief Connection to render tear down event callback
public: gz::common::ConnectionPtr teardownConnection{nullptr};

/// \brief Name of visual this plugin is attached to
public: std::string visualName;

Expand Down Expand Up @@ -118,6 +121,9 @@ class gz::sim::systems::ShaderParamPrivate

/// \brief All rendering operations must happen within this call
public: void OnUpdate();

/// \brief Callback to rendering engine tear down
public: void OnRenderTeardown();
};

/////////////////////////////////////////////////
Expand Down Expand Up @@ -246,6 +252,10 @@ void ShaderParam::Configure(const Entity &_entity,
this->dataPtr->connection =
_eventMgr.Connect<gz::sim::events::SceneUpdate>(
std::bind(&ShaderParamPrivate::OnUpdate, this->dataPtr.get()));

this->dataPtr->teardownConnection =
_eventMgr.Connect<gz::sim::events::RenderTeardown>(
std::bind(&ShaderParamPrivate::OnRenderTeardown, this->dataPtr.get()));
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -496,6 +506,14 @@ void ShaderParamPrivate::OnUpdate()
}
}

//////////////////////////////////////////////////
void ShaderParamPrivate::OnRenderTeardown()
{
this->visual.reset();
this->scene.reset();
this->material.reset();
}

GZ_ADD_PLUGIN(ShaderParam,
gz::sim::System,
ShaderParam::ISystemConfigure,
Expand Down

0 comments on commit 197596a

Please sign in to comment.