Skip to content

Commit

Permalink
qgs3daxis: Fix object root memory leak
Browse files Browse the repository at this point in the history
If an object root entity (`mCubeRoot` or `mAxisRoot`) is not enabled,
it means that it does not have a parent because of the
`setEnableCube()` and `setEnableAxis()` logic. In that case, it will
never be automatically deleted by Qt. Therefore, it creates a memory
leak.

This issue is fixed by adding a check in the destructor. If an object
is not enabled, then it is disabled.
  • Loading branch information
ptitjano authored and nyalldawson committed Jun 27, 2024
1 parent 3997f0e commit b578f1e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/3d/qgs3daxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ Qgs3DAxis::~Qgs3DAxis()
{
delete mMenu;
mMenu = nullptr;

// If a root entity is not enabled, it means that it does not have a parent.
// In that case, it will never be automatically deleted. Therefore, it needs to be manually deleted.
// See setEnableCube() and setEnableAxis().
if ( !mCubeRoot->isEnabled() )
{
delete mCubeRoot;
mCubeRoot = nullptr;
}

if ( !mAxisRoot->isEnabled() )
{
delete mAxisRoot;
mAxisRoot = nullptr;
}
}

void Qgs3DAxis::init3DObjectPicking( )
Expand Down

0 comments on commit b578f1e

Please sign in to comment.