From 4dcb02731afb803a940903f401f991690b7fdf31 Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Tue, 14 Apr 2026 09:57:41 +0200 Subject: [PATCH 1/3] Let TGLabel::fHasOwnFont only if really allocate TGGC In batch mode fNormGC is 0 and therefore not equal to the GetDefaultGC(). But in destructor fHasOwnFont used to delete gc object which not allocated by TGLabel --- gui/gui/src/TGLabel.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/gui/src/TGLabel.cxx b/gui/gui/src/TGLabel.cxx index 9c309c0cbf2e1..7875c1c4b2af2 100644 --- a/gui/gui/src/TGLabel.cxx +++ b/gui/gui/src/TGLabel.cxx @@ -340,8 +340,8 @@ void TGLabel::SetTextFont(TGFont *font, Bool_t global) if (!global) { if (gc == &GetDefaultGC() ) { // create new GC gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy ctor. + fHasOwnFont = kTRUE; } - fHasOwnFont = kTRUE; } if (oldfont != fgDefaultFont) { fClient->FreeFont(oldfont); @@ -366,8 +366,8 @@ void TGLabel::SetTextColor(Pixel_t color, Bool_t global) if (!global) { if (gc == &GetDefaultGC() ) { gc = pool->GetGC((GCValues_t*)gc->GetAttributes(), kTRUE); // copy + fHasOwnFont = kTRUE; } - fHasOwnFont = kTRUE; } if (gc) { gc->SetForeground(color); From 08163c1269d9a087c8f4000989203e7a03bfe8ef Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Tue, 14 Apr 2026 10:00:42 +0200 Subject: [PATCH 2/3] Always assign ref count in TGGC constructor In any situation such created TGGC instance should have proper ref count value --- gui/gui/src/TGGC.cxx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/gui/gui/src/TGGC.cxx b/gui/gui/src/TGGC.cxx index 0078ccf465c5c..7d5b52071a2a9 100644 --- a/gui/gui/src/TGGC.cxx +++ b/gui/gui/src/TGGC.cxx @@ -50,7 +50,6 @@ TGGC::TGGC(GCValues_t *values, Bool_t) } } else { fValues = {}; - fContext = 0; } SetRefCount(1); } @@ -61,20 +60,14 @@ TGGC::TGGC(GCValues_t *values, Bool_t) TGGC::TGGC(GCValues_t *values) { fContext = 0; + SetRefCount(1); // case of default ctor at program startup before gClient exists - if (!values) { + if (!values) fValues = {}; - fContext = 0; - SetRefCount(1); - return; - } - - if (gClient) + else if (gClient) gClient->GetGC(values, kTRUE); - else { - fContext = 0; + else Error("TGGC", "TGClient not yet initialized, should never happen"); - } } //////////////////////////////////////////////////////////////////////////////// From fb1d2694458cb571071a9ce2f8954609b52c7ce6 Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Tue, 14 Apr 2026 10:11:27 +0200 Subject: [PATCH 3/3] Let return dummy TGPicture in batch mode In batch real pixmap manipulation is not possible. But all instances of TGPicture are created. In normal mode they are "hidden", but in batch one can return pointer on the picture to suppress many errors printout in the TG.. classes By the way - by the first call of `TGPicturePool::GetPicture()` also dummy ` TGPicture` is returned --- gui/gui/src/TGPicture.cxx | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/gui/gui/src/TGPicture.cxx b/gui/gui/src/TGPicture.cxx index 1b4d74771dc8a..2776dbb6387ce 100644 --- a/gui/gui/src/TGPicture.cxx +++ b/gui/gui/src/TGPicture.cxx @@ -94,42 +94,36 @@ const TGPicture *TGPicturePool::GetPicture(const char *name) TGPicture *pic = (TGPicture *)fPicList->FindObject(pname); if (pic && !pic->IsScaled()) { - if (pic->fPic == kNone) - return 0; + // in batch mode allow to return dummy image + if ((pic->fPic == kNone) && !gROOT->IsBatch()) + return nullptr; pic->AddReference(); return pic; } char *picnam = gSystem->Which(fPath, pname, kReadPermission); - if (!picnam) { - pic = new TGPicture(pname); - pic->fAttributes.fColormap = fClient->GetDefaultColormap(); - pic->fAttributes.fCloseness = 40000; // Allow for "similar" colors - pic->fAttributes.fMask = kPASize | kPAColormap | kPACloseness; - fPicList->Add(pic); - return 0; - } - TImage *img = TImage::Open(picnam); + TImage *img = picnam ? TImage::Open(picnam) : nullptr; + + delete [] picnam; + if (!img) { pic = new TGPicture(pname); pic->fAttributes.fColormap = fClient->GetDefaultColormap(); pic->fAttributes.fCloseness = 40000; // Allow for "similar" colors pic->fAttributes.fMask = kPASize | kPAColormap | kPACloseness; fPicList->Add(pic); - delete [] picnam; - return 0; + return nullptr; } pic = new TGPicture(pname, img->GetPixmap(), img->GetMask()); - delete [] picnam; delete img; fPicList->Add(pic); return pic; } //////////////////////////////////////////////////////////////////////////////// -/// Like TGPicturePool::GetPicture() but, instead of returning null when the +/// Like TGPicturePool::GetPicture() but, instead of returning null when the /// picture is not found, it returns a valid empty picture. const TGPicture *TGPicturePool::GetPictureOrEmpty(const char *name)