Skip to content

Fix cppcheck warnings, typos, style issues#1227

Merged
iche033 merged 2 commits intogazebosim:gz-rendering10from
ntfshard:variousfixes
Jan 28, 2026
Merged

Fix cppcheck warnings, typos, style issues#1227
iche033 merged 2 commits intogazebosim:gz-rendering10from
ntfshard:variousfixes

Conversation

@ntfshard
Copy link
Contributor

@ntfshard ntfshard commented Jan 25, 2026

🦟 Bug fix

Fixes #

Summary

I'm running CppCheck with compile_commands.json file which generated by cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON (and manual path tweak to run scan on host), not make cppcheck

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
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

Copy link
Contributor Author

@ntfshard ntfshard left a comment

Choose a reason for hiding this comment

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

Follow-up questions:

A:
Fix for next warnings or can break ABI or need some clarification. I'd like to discuss it separately and PR(s) can be done in main for example:

  • Member variable 'MapFunctionEnum::variants' is not assigned a value in 'MapFunctionEnum::operator='.
    Not clear, is it intentional or mistake. If it's intentional, maybe better left comment. Or maybe make it not copy assignable(just move). Or just use =default if it's mistake

  • Class 'SceneExt' which has virtual members does not have a virtual destructor.
    gz-rendering/include/gz/rendering/base/SceneExt.hh:45
    (change ABI, but seems should be changed)

  • The class 'BaseParticleEmitter < Ogre2Visual >' defines member variable with name 'material' also defined in its parent class 'BaseVisual < Ogre2Node >'.
    (change ABI, but seems should be removed one, or maybe it should be 2 different and need another name in this case)

  • Hiding warning in cppcheck, maybe virtual is missing?
    The class 'OgreCOMVisual' defines member function with name 'OgreObject' also defined in its parent class 'OgreObject'.
    The class 'OgreInertiaVisual' defines member function with name 'OgreObject' also defined in its parent class 'OgreObject'.
    The class 'OgreLightVisual' defines member function with name 'OgreObject' also defined in its parent class 'OgreObject'.

B:
What do you think about adding GZ_PROFILER for renders? It can have more realistic picture of performance problem with rendering sensors or GUI part? I mean, I can do it, just want to check that this change can be accepted to the codebase. And which branch should be targeted. We are using stable release to be honest.

/////////////////////////////////////////////////
gz::math::AxisAlignedBox transformAxisAlignedBox(
const gz::math::AxisAlignedBox &_bbox,
const gz::math::AxisAlignedBox &_box,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems _box is more common in this repo

Comment on lines +171 to +174
for (unsigned int i = 0; i < 6; ++i)
{
this->ogreCompositorWorkspace[i] = nullptr;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CppCheck warning, technically it was initialized in other place, just moved it from parent's constructor. Technically same result can get in a shorter way, not only explicit code. But left it as is for simplicity.

size_t idx = meshName.find("::");
if (idx != std::string::npos)
meshName = meshName.substr(0, idx);
meshName.resize(idx);
Copy link
Contributor Author

@ntfshard ntfshard Jan 25, 2026

Choose a reason for hiding this comment

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

also cppcheck warning;
live example: https://godbolt.org/z/9vfKnEqav

"The number of supported emitters does not match the number of "
"Ogre emitter types.");

GZ_ASSERT(this->type < kOgreEmitterTypes.size(), "Unknown emitter type");
Copy link
Contributor Author

@ntfshard ntfshard Jan 25, 2026

Choose a reason for hiding this comment

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

in other method similar check exist. So it's nice to have it here too. Not very accessible outside, so it should be safe to have assert and not runtime return.

Comment on lines 884 to -885
math::Vector3d ray(0, 0, 1);
ray.Normalize();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems it should be the same unit vector after Normalize. Seems we can get rid of this call

int index = 0;
for (unsigned int i = 0; i < this->dataPtr->h2nd; ++i)
{
const math::Quaterniond pitch(math::Vector3d(1, 0, 0), -v);
Copy link
Contributor Author

@ntfshard ntfshard Jan 25, 2026

Choose a reason for hiding this comment

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

Invariant moved out of the nested loop

#ifndef GZ_RENDERING_OGRE2_OGRE2GPURAYS_HH_
#define GZ_RENDERING_OGRE2_OGRE2GPURAYS_HH_

#include <functional>
Copy link
Contributor Author

@ntfshard ntfshard Jan 25, 2026

Choose a reason for hiding this comment

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

for std::function, guess should be fixed in multiple places, better with include-what-you-use but not in this PR

@ntfshard ntfshard force-pushed the variousfixes branch 2 times, most recently from 3c5b6c0 to 65506ed Compare January 25, 2026 17:47
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
@iche033
Copy link
Contributor

iche033 commented Jan 26, 2026

Thanks for the fixes! Changes look good to me.

Member variable 'MapFunctionEnum::variants' is not assigned a value in 'MapFunctionEnum::operator='.

Looking at the code, I think variants is tmp variable is that is set up in the constructor and used only to determine what value should be. It does not need to be copied in operator=.

Class 'SceneExt' which has virtual members does not have a virtual destructor.

yes, we can add virtual destructor but in main branch

The class 'BaseParticleEmitter < Ogre2Visual >' defines member variable with name 'material' also defined in its parent class 'BaseVisual < Ogre2Node >'.

For this particular class, we could remove the material variable in the BaseParticleEmitter class. The material member variable is not really needed in the ogre2 implementation. It gets immediately converted to this->dataPtr->ogreDatablock (Ogre::HlmsUnlitDatablock) in SetMaterial. On the other hand, this would break other people's code / render engine implementation. This change would need to go in main with an entry in the Migration.md guide.

Hiding warning in cppcheck, maybe virtual is missing?

yes looks like they should be overriding the functions from base class

What do you think about adding GZ_PROFILER for renders?

I think it's a good idea. Good to provide more finer profiling points with GZ_PROFILER for remotery, especially for functions like *::Render(). I'm ok with targeting stable branch and as it does not change behavior or break API/ABI.

@github-project-automation github-project-automation bot moved this from Inbox to In review in Core development Jan 26, 2026
@azeey
Copy link

azeey commented Jan 26, 2026

@ntfshard Thanks for the PR! Since we use the PR title as the changelog entry, could you please make it more descriptive?

@ntfshard
Copy link
Contributor Author

ntfshard commented Jan 27, 2026

Member variable 'MapFunctionEnum::variants' is not assigned a value in 'MapFunctionEnum::operator='.

Looking at the code, I think variants is tmp variable is that is set up in the constructor and used only to determine what value should be. It does not need to be copied in operator=.

But it will be copied in case of copy constructor: https://godbolt.org/z/KMeYonPKh
I'll check, can we =delete for assignment operator, maybe we don't need it in general (upd: no we need it)
(about auto-generated methods https://stackoverflow.com/a/59616399/2230159 scheme)
Maybe add custom copy ctor to make it even?

On the other hand, this would break other people's code / render engine implementation. This change would need to go in main with an entry in the Migration.md guide.

Render is still quite isolated part but if someone using it through parent type, it should looks like not working. I guess we can clarify details in a follow-up PR

@ntfshard Thanks for the PR! Since we use the PR title as the changelog entry, could you please make it more descriptive?

I'll change it. I'm not native English speaker, feel free to correct it for better naming


Just noticed, warning with OgreObject() is much more interesting. It's a constructor of parent object and method in child. I guess virtual won't help us here C:

And about BaseParticleEmitter, I really not sure in general. Like I see some more or less clear interface. And removing it could make more confusion. Maybe in general all interfaces could be simplified. I mean, if we need virtual inheritance it's already looks like se have a graph, not a tree. Which makes understanding quite tricky.

I'll put small PR for virtual dtor to main as a most obvious problem&solution. #1229

@ntfshard ntfshard changed the title Various fixes Fix for warnings Jan 27, 2026
@ntfshard
Copy link
Contributor Author

ntfshard commented Jan 28, 2026

Member variable 'MapFunctionEnum::variants' is not assigned a value in 'MapFunctionEnum::operator='.

Looking at the code, I think variants is tmp variable is that is set up in the constructor and used only to determine what value should be. It does not need to be copied in operator=.

To make behaviour more clear for further development, left comment and disabled copy constructor

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
@iche033
Copy link
Contributor

iche033 commented Jan 28, 2026

I mean, if we need virtual inheritance it's already looks like se have a graph, not a tree. Which makes understanding quite tricky.

yes that inheritance architecture is something I've considered refactoring / removing for a while (related to #22). It's a big effort which unfortunately we didn't have time to do.

To make behaviour more clear for further development, left comment and disabled copy constructor

looks good to me

@iche033 iche033 changed the title Fix for warnings Fix cppcheck warnings, typos, style issues Jan 28, 2026
@iche033
Copy link
Contributor

iche033 commented Jan 28, 2026

I'll merge this first as it's already a big PR. Other changes can come in follow-up PRs.

@iche033 iche033 merged commit a395a95 into gazebosim:gz-rendering10 Jan 28, 2026
13 of 14 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Core development Jan 28, 2026
@iche033
Copy link
Contributor

iche033 commented Jan 28, 2026

@Mergifyio backport main gz-rendering9 gz-rendering8

@mergify
Copy link
Contributor

mergify bot commented Jan 28, 2026

backport main gz-rendering9 gz-rendering8

✅ Backports have been created

Details

Cherry-pick of a395a95 has failed:

On branch mergify/bp/gz-rendering8/pr-1227
Your branch is up to date with 'origin/gz-rendering8'.

You are currently cherry-picking commit a395a952.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   examples/camera_tracking/GlutWindow.cc
	modified:   examples/lidar_visual/GlutWindow.cc
	modified:   include/gz/rendering/OrbitViewController.hh
	modified:   include/gz/rendering/OrthoViewController.hh
	modified:   include/gz/rendering/base/BaseBoundingBoxCamera.hh
	modified:   include/gz/rendering/base/BaseCamera.hh
	modified:   include/gz/rendering/base/BaseDepthCamera.hh
	modified:   include/gz/rendering/base/BaseDistortionPass.hh
	modified:   include/gz/rendering/base/BaseGaussianNoisePass.hh
	modified:   include/gz/rendering/base/BaseGeometry.hh
	modified:   include/gz/rendering/base/BaseGpuRays.hh
	modified:   include/gz/rendering/base/BaseGrid.hh
	modified:   include/gz/rendering/base/BaseLight.hh
	modified:   include/gz/rendering/base/BaseLightVisual.hh
	modified:   include/gz/rendering/base/BaseMaterial.hh
	modified:   include/gz/rendering/base/BaseRenderTarget.hh
	modified:   include/gz/rendering/base/BaseText.hh
	modified:   include/gz/rendering/base/BaseThermalCamera.hh
	modified:   include/gz/rendering/base/BaseWireBox.hh
	modified:   ogre/include/gz/rendering/ogre/OgreDynamicLines.hh
	modified:   ogre/include/gz/rendering/ogre/OgreGeometry.hh
	modified:   ogre/include/gz/rendering/ogre/OgreGrid.hh
	modified:   ogre/include/gz/rendering/ogre/OgreLight.hh
	modified:   ogre/include/gz/rendering/ogre/OgreProjector.hh
	modified:   ogre/include/gz/rendering/ogre/OgreRenderEngine.hh
	modified:   ogre/src/OgreConversions.cc
	modified:   ogre/src/OgreDistortionPass.cc
	modified:   ogre/src/OgreHeightmap.cc
	modified:   ogre/src/OgreLidarVisual.cc
	modified:   ogre/src/OgreMaterial.cc
	modified:   ogre/src/OgreMesh.cc
	modified:   ogre/src/OgreMeshFactory.cc
	modified:   ogre/src/OgreProjector.cc
	modified:   ogre/src/OgreRTShaderSystem.cc
	modified:   ogre/src/OgreRayQuery.cc
	modified:   ogre/src/OgreRenderPass.cc
	modified:   ogre/src/OgreText.cc
	modified:   ogre/src/OgreVisual.cc
	modified:   ogre2/include/gz/rendering/ogre2/Ogre2GpuRays.hh
	modified:   ogre2/include/gz/rendering/ogre2/Ogre2Grid.hh
	modified:   ogre2/include/gz/rendering/ogre2/Ogre2ParticleEmitter.hh
	modified:   ogre2/include/gz/rendering/ogre2/Ogre2RenderEngine.hh
	modified:   ogre2/include/gz/rendering/ogre2/Ogre2RenderPass.hh
	modified:   ogre2/include/gz/rendering/ogre2/Ogre2RenderTargetMaterial.hh
	modified:   ogre2/include/gz/rendering/ogre2/Ogre2Sensor.hh
	modified:   ogre2/include/gz/rendering/ogre2/Ogre2WideAngleCamera.hh
	modified:   ogre2/src/Ogre2BoundingBoxCamera.cc
	modified:   ogre2/src/Ogre2BoundingBoxMaterialSwitcher.cc
	modified:   ogre2/src/Ogre2Conversions.cc
	modified:   ogre2/src/Ogre2DepthCamera.cc
	modified:   ogre2/src/Ogre2GpuRays.cc
	modified:   ogre2/src/Ogre2LensFlarePass.cc
	modified:   ogre2/src/Ogre2Marker.cc
	modified:   ogre2/src/Ogre2Material.cc
	modified:   ogre2/src/Ogre2MeshFactory.cc
	modified:   ogre2/src/Ogre2ParticleEmitter.cc
	modified:   ogre2/src/Ogre2Projector.cc
	modified:   ogre2/src/Ogre2RayQuery.cc
	modified:   ogre2/src/Ogre2RenderEngine.cc
	modified:   ogre2/src/Ogre2RenderPass.cc
	modified:   ogre2/src/Ogre2Scene.cc
	modified:   ogre2/src/Ogre2SegmentationMaterialSwitcher.cc
	modified:   ogre2/src/Ogre2WideAngleCamera.cc
	modified:   src/CameraLens.cc
	modified:   src/OrbitViewController.cc
	modified:   src/RenderEngineManager.cc
	modified:   src/TransformController.cc
	modified:   src/Utils.cc

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   ogre/src/OgreFrustumVisual.cc
	both modified:   ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

mergify bot pushed a commit that referenced this pull request Jan 28, 2026
Reducing CppCheck report size, frequent warnings:
* missing override (CI-clang seems also affected by this)
* different argument name
* variable scope can be reduced
* Ogre or containers in standard library most of times use size_t, better to use
* Fix typos
* In general tried to follow the rule from c++ core guidelines https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c128-virtual-functions-should-specify-exactly-one-of-virtual-override-or-final (but changing it in all code could make PR much bigger)

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit a395a95)
mergify bot pushed a commit that referenced this pull request Jan 28, 2026
Reducing CppCheck report size, frequent warnings:
* missing override (CI-clang seems also affected by this)
* different argument name
* variable scope can be reduced
* Ogre or containers in standard library most of times use size_t, better to use
* Fix typos
* In general tried to follow the rule from c++ core guidelines https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c128-virtual-functions-should-specify-exactly-one-of-virtual-override-or-final (but changing it in all code could make PR much bigger)

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit a395a95)
mergify bot pushed a commit that referenced this pull request Jan 28, 2026
Reducing CppCheck report size, frequent warnings:
* missing override (CI-clang seems also affected by this)
* different argument name
* variable scope can be reduced
* Ogre or containers in standard library most of times use size_t, better to use
* Fix typos
* In general tried to follow the rule from c++ core guidelines https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c128-virtual-functions-should-specify-exactly-one-of-virtual-override-or-final (but changing it in all code could make PR much bigger)

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit a395a95)

# Conflicts:
#	ogre/src/OgreFrustumVisual.cc
#	ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh
@ntfshard ntfshard deleted the variousfixes branch January 29, 2026 04:28
iche033 pushed a commit that referenced this pull request Jan 29, 2026
Reducing CppCheck report size, frequent warnings:
* missing override (CI-clang seems also affected by this)
* different argument name
* variable scope can be reduced
* Ogre or containers in standard library most of times use size_t, better to use
* Fix typos
* In general tried to follow the rule from c++ core guidelines https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c128-virtual-functions-should-specify-exactly-one-of-virtual-override-or-final (but changing it in all code could make PR much bigger)

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit a395a95)
iche033 pushed a commit that referenced this pull request Jan 29, 2026
Reducing CppCheck report size, frequent warnings:
* missing override (CI-clang seems also affected by this)
* different argument name
* variable scope can be reduced
* Ogre or containers in standard library most of times use size_t, better to use
* Fix typos
* In general tried to follow the rule from c++ core guidelines https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c128-virtual-functions-should-specify-exactly-one-of-virtual-override-or-final (but changing it in all code could make PR much bigger)

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit a395a95)
iche033 added a commit that referenced this pull request Jan 29, 2026
Signed-off-by: Ian Chen <ichen@openrobotics.org>
iche033 added a commit that referenced this pull request Jan 30, 2026
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants