You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmsHeader causes segmentation violation using ROOT v6.40 #77
On new versions of python and ROOT, using the cmsHeader function results in a corrupted canvas where the buffer of the header is freed by python garbage collection. Attached is a minimal reproducer and a simplistic fix. My system information is:
ROOT version information
ROOT Version: 6.40.00
Built for linuxx8664gcc on May 22 2026, 18:02:23
From tags/6-40-00@6-40-00
Python version information
Python 3.14.5
cmsstyle version information
uv pip show cmsstyle
Using Python 3.14.5 environment at: ...
Name: cmsstyle
Version: 0.5.0
Location: ...
Requires: typing-extensions
Required-by:
Reproducer
#!/usr/bin/env python3
import cmsstyle as cms
import ROOT as rt
def fixed_cmsHeader(
leg,
legTitle,
textAlign=12,
textSize=0.04,
textFont=42,
textColor=rt.kBlack,
isToRemove=True,
):
header = rt.TLegendEntry(0, legTitle, "h")
header.SetTextFont(textFont)
header.SetTextSize(textSize)
header.SetTextAlign(textAlign)
header.SetTextColor(textColor)
if isToRemove:
leg.SetHeader(legTitle, "C")
leg.GetListOfPrimitives().Remove(leg.GetListOfPrimitives().At(0))
leg.GetListOfPrimitives().AddAt(header, 0)
else:
leg.GetListOfPrimitives().AddLast(header)
rt.SetOwnership(
header, False
) # This otherwise gets garbage collected as of ROOT 6.40 and python 3.14
def show_with_legend(header_text, header_func):
canvas = cms.cmsCanvas("canvas", 0, 1, 0, 1, "x", "y")
leg = cms.cmsLeg(0.2, 0.2, 0.8, 0.8)
header_func(leg, header_text)
canvas.Update()
canvas.Draw()
def run_reproducer():
show_with_legend("Test header text", fixed_cmsHeader)
input("A working canvas with a header is now visible. Press return to trigger crash")
print(
"Attempting to paint the canvas with a cmsHeader triggers segv.\n"
"Python garbage collection is at the same time already freeing the header."
)
show_with_legend("Broken header text", cms.cmsHeader)
input("Version not affected. Press return to exit.")
run_reproducer()
Activity
ttedeschi commentedon May 28, 2026
Thank you @aapo-kossi for spotting this crash in the brand new ROOT release v6.40.. this new ownership behavior is indeed mentioned in v6.40 release notes https://root.cern.ch/doc/v640/release-notes.html#change-in-memory-ownership-heuristics
Thank you for providing a minimal reproducer and a simplistic fix, too. I will solve this issue in a new PR!
ttedeschi commentedon May 28, 2026
Fixed by #78