Skip to content

Commit

Permalink
[gpad] Implement TRatioPlot::RecursiveRemove
Browse files Browse the repository at this point in the history
TRatioPlot object was registered in list of cleanups,
but recursive remove was not implemented.
Therefore if any internal object was deleted before -
it make problem.

Fixes issue root-project#14855
  • Loading branch information
linev committed Feb 29, 2024
1 parent 7571a60 commit 741896c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions graf2d/gpad/inc/TRatioPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class TRatioPlot : public TObject {
void Draw(Option_t *chopt = "") override;
void Browse(TBrowser *b) override;

void RecursiveRemove(TObject *obj) override;

void Paint(Option_t *opt = "") override;

Expand Down
35 changes: 31 additions & 4 deletions graf2d/gpad/src/TRatioPlot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ TRatioPlot::TRatioPlot()

TRatioPlot::~TRatioPlot()
{

gROOT->GetListOfCleanups()->Remove(this);

auto safeDelete = [](TObject *obj) {
Expand All @@ -120,9 +119,8 @@ TRatioPlot::~TRatioPlot()
safeDelete(fConfidenceInterval1);
safeDelete(fConfidenceInterval2);

for (unsigned int i=0;i<fGridlines.size();++i) {
delete (fGridlines[i]);
}
for (auto &line : fGridlines)
safeDelete(line);

safeDelete(fSharedXAxis);
safeDelete(fUpperGXaxis);
Expand All @@ -138,6 +136,35 @@ TRatioPlot::~TRatioPlot()
safeDelete(fLowYaxis);
}

////////////////////////////////////////////////////////////////////////////////
/// Handle recursive remove of objects

void TRatioPlot::RecursiveRemove(TObject *obj)
{
if (!obj) return;

if (fRatioGraph == obj) fRatioGraph = nullptr;

if (fConfidenceInterval1 == obj) fConfidenceInterval1 = nullptr;
if (fConfidenceInterval1 == obj) fConfidenceInterval1 = nullptr;

for (auto &line : fGridlines)
if (line == obj) line = nullptr;

if (fSharedXAxis == obj) fSharedXAxis = nullptr;
if (fUpperGXaxis == obj) fUpperGXaxis = nullptr;
if (fLowerGXaxis == obj) fLowerGXaxis = nullptr;
if (fUpperGYaxis == obj) fUpperGYaxis = nullptr;
if (fLowerGYaxis == obj) fLowerGYaxis = nullptr;
if (fUpperGXaxisMirror == obj) fUpperGXaxisMirror = nullptr;
if (fLowerGXaxisMirror == obj) fLowerGXaxisMirror = nullptr;
if (fUpperGYaxisMirror == obj) fUpperGYaxisMirror = nullptr;
if (fLowerGYaxisMirror == obj) fLowerGYaxisMirror = nullptr;

if (fUpYaxis == obj) fUpYaxis = nullptr;
if (fLowYaxis == obj) fLowYaxis = nullptr;
}

////////////////////////////////////////////////////////////////////////////////
/// Internal method that shares constructor logic

Expand Down

0 comments on commit 741896c

Please sign in to comment.