Skip to content

Conversation

XINJIANGMO
Copy link
Contributor

🦟 Bug fix

Fixes #3131

Summary

When adding a light via Component Inspector Editor, the created entity ends up with a Visual component but no valid Geometry. RenderUtil::CreateVisual assumes Geometry is present and calls visual.SetGeom(_geom->Data()), causing a crash.

This fix return early when _geom is nullptr , avoiding the crash in SetGeom, while not affecting light creation

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • 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

Signed-off-by: momo <2438833481@qq.com>
@XINJIANGMO XINJIANGMO requested a review from iche033 as a code owner October 19, 2025 03:36
@XINJIANGMO XINJIANGMO changed the title Fix crash by adding nullptr check Fix crash when adding a Light via Component Inspector Editor Oct 19, 2025
@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Oct 20, 2025
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@ahcorde ahcorde enabled auto-merge (squash) October 20, 2025 07:12
sdf::Visual visual;
visual.SetName(_name->Data());
visual.SetRawPose(_pose->Data());
if(!_geom)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this check can be moved to the start of the function, i.e. before sdf::Visual visual

@XINJIANGMO
Copy link
Contributor Author

XINJIANGMO commented Oct 21, 2025

Sorry , I do some tests after this fix , but when I rerun the simulation after I add a light to a model , it crashes again.
This is the crash.log.
From the stack , When we rerun the simulation, EntityComponentManager will call nameComp->Data() without checking if it exists.
There may be a better solution for this issue!

@XINJIANGMO XINJIANGMO requested a review from iche033 October 21, 2025 04:08
@XINJIANGMO
Copy link
Contributor Author

XINJIANGMO commented Oct 21, 2025

Also, I find that when I use add function via Component Inspector Editor without pausing, it will not pop up Tip Dialog but stuck.
I test it in gz-sim9 and it works well.
image
If developers confirm these , I can try my best to find and fix it.

@XINJIANGMO XINJIANGMO requested a review from ahcorde October 21, 2025 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants