Segmentation Violation with createNLL

Hello,
I am running a code that was working few weeks ago, but now for some reason I get a segmentation violation when saving the canva.

Here’s a code snippet:

        def draw_sigma_lines(frame, legend, value, err, sigma, color):
            min_val = frame.GetMinimum()
            max_val = frame.GetMaximum()

            for sign in [+1, -1]:
                line = R.TLine(value + sign * sigma * err, min_val, value + sign * sigma * err, max_val)
                line.SetLineColor(color)
                line.SetLineWidth(2)
                line.Draw("same")
            legend.AddEntry(line, f"#pm {sigma}#sigma", "l")

        legend = R.TLegend(0.6, 0.7, 0.9, 0.9)
        nll = pdf_model.createNLL(pseudo_data, RF.Extended(R.kTRUE))
        x_i = pdf_model.getVariables().find("n_Bcp2taup2pipipi")

        minimizer = R.RooMinimizer(nll)
        minimizer.setStrategy(2)
        minimizer.setMaxFunctionCalls(20000)
        minimizer.setPrintLevel(-1)
        minimizer.minimize("Minuit2", "migrad")
        minimizer.minos()
        minimizer_result = minimizer.save()
        minimizer_result.Print()

        val_i = x_i.getVal()
        err_i = x_i.getError()

        frame = x_i.frame(RF.Range(val_i - 5*err_i, val_i + 5*err_i))

        pll = nll.createProfile(x_i)
        pll.plotOn(frame, RF.LineColor(R.kRed))
        
        c = R.TCanvas("profile_likelihood", "Profile Likelihood", 800, 400)
        c.cd()
        
        frame.Draw()
        
        draw_sigma_lines(frame, legend, val_i, err_i, 1, R.kCyan + 2)
        draw_sigma_lines(frame, legend, val_i, err_i, 2, R.kMagenta + 2)
        
        legend.Draw("same")

        c.SaveAs(f"{output_now}_NLL.pdf")
        c.Close()

and here’s the output: (note: it disappears if I comment the line with SaveAs)

*** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================

Thread 41 (Thread 0x7f636341f640 (LWP 2078573) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f647a119e28 in th_worker(void*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numexpr/interpreter.cpython-312-x86_64-linux-gnu.so
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 40 (Thread 0x7f6363c20640 (LWP 2078572) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f647a119e28 in th_worker(void*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numexpr/interpreter.cpython-312-x86_64-linux-gnu.so
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6
...

Thread 25 (Thread 0x7f640cfe9640 (LWP 2078449) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 24 (Thread 0x7f640d7ea640 (LWP 2078448) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 23 (Thread 0x7f640dfeb640 (LWP 2078447) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 22 (Thread 0x7f641e7ec640 (LWP 2078446) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 21 (Thread 0x7f641efed640 (LWP 2078445) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 20 (Thread 0x7f641f7ee640 (LWP 2078444) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 19 (Thread 0x7f641ffef640 (LWP 2078443) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 18 (Thread 0x7f64207f0640 (LWP 2078442) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 17 (Thread 0x7f6420ff1640 (LWP 2078441) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 16 (Thread 0x7f64217f2640 (LWP 2078440) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 15 (Thread 0x7f6421ff3640 (LWP 2078439) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 14 (Thread 0x7f64227f4640 (LWP 2078438) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 13 (Thread 0x7f642aff5640 (LWP 2078437) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 12 (Thread 0x7f642b7f6640 (LWP 2078436) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 11 (Thread 0x7f643bff7640 (LWP 2078435) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 10 (Thread 0x7f643c7f8640 (LWP 2078434) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 9 (Thread 0x7f6444ff9640 (LWP 2078433) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 8 (Thread 0x7f644d7fa640 (LWP 2078432) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 7 (Thread 0x7f6455ffb640 (LWP 2078431) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 6 (Thread 0x7f645e7fc640 (LWP 2078430) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 5 (Thread 0x7f6466ffd640 (LWP 2078429) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 4 (Thread 0x7f646f7fe640 (LWP 2078428) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 3 (Thread 0x7f646ffff640 (LWP 2078427) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c890c0 in pthread_cond_wait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x00007f6474582964 in blas_thread_server () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/numpy/core/../../../../libcblas.so.3
#3  0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#4  0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 2 (Thread 0x7f6477946640 (LWP 2078426) "python"):
#0  0x00007f64a8c868ba in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1  0x00007f64a8c893c4 in pthread_cond_timedwait

GLIBC_2.3.2 () from /lib64/libc.so.6
#2  0x000055689350dd9b in PyCOND_TIMEDWAIT (us=<optimized out>, mut=<optimized out>, cond=0x55689395cb88 <_PyRuntime+77512>) at /usr/local/src/conda/python-3.12.4/Python/condvar.h:73
#3  take_gil (tstate=tstate
entry=0x55689a0e9750) at /usr/local/src/conda/python-3.12.4/Python/ceval_gil.c:376
#4  0x0000556893532372 in PyEval_RestoreThread (tstate=tstate
entry=0x55689a0e9750) at /usr/local/src/conda/python-3.12.4/Python/ceval_gil.c:708
#5  0x0000556893665f42 in pysleep (timeout=<optimized out>) at /usr/local/src/conda/python-3.12.4/Modules/timemodule.c:2198
#6  time_sleep (self=<optimized out>, timeout_obj=<optimized out>) at /usr/local/src/conda/python-3.12.4/Modules/timemodule.c:425
#7  0x000055689343339c in _PyEval_EvalFrameDefault (tstate=tstate
entry=0x55689a0e9750, frame=0x7f648f80e188, frame
entry=0x7f648f80e020, throwflag=throwflag
entry=0) at Python/bytecodes.c:2912
#8  0x00005568935766dc in _PyEval_EvalFrame (throwflag=0, frame=0x7f648f80e020, tstate=0x55689a0e9750) at /usr/local/src/conda/python-3.12.4/Include/internal/pycore_ceval.h:89
#9  _PyEval_Vector (kwnames=0x0, argcount=1, args=0x7f6477945da8, locals=0x0, func=0x7f649b5b8180, tstate=0x55689a0e9750) at /usr/local/src/conda/python-3.12.4/Python/ceval.c:1683
#10 _PyFunction_Vectorcall (kwnames=0x0, nargsf=<optimized out>, stack=0x7f6477945da8, func=0x7f649b5b8180) at /usr/local/src/conda/python-3.12.4/Objects/call.c:419
#11 _PyObject_VectorcallTstate (tstate=<optimized out>, callable=0x7f649b5b8180, args=0x7f6477945da8, nargsf=<optimized out>, kwnames=0x0) at /usr/local/src/conda/python-3.12.4/Include/internal/pycore_call.h:92
#12 0x0000556893576288 in method_vectorcall (method=<optimized out>, args=0x55689395c6f0 <_PyRuntime+76336>, nargsf=0, kwnames=0x0) at /usr/local/src/conda/python-3.12.4/Objects/classobject.c:69
#13 0x0000556893658b82 in thread_run (boot_raw=0x55689ae9d050) at /usr/local/src/conda/python-3.12.4/Modules/_threadmodule.c:1114
#14 0x00005568936168e4 in pythread_wrapper (arg=<optimized out>) at /usr/local/src/conda/python-3.12.4/Python/thread_pthread.h:237
#15 0x00007f64a8c89d22 in start_thread () from /lib64/libc.so.6
#16 0x00007f64a8d0ed40 in clone3 () from /lib64/libc.so.6

Thread 1 (Thread 0x7f64a8f97740 (LWP 2078281) "python"):
#0  0x00007f64a8cd8b3f in wait4 () from /lib64/libc.so.6
#1  0x00007f64a8c4b283 in do_system () from /lib64/libc.so.6
#2  0x00007f649aec6a9d in TUnixSystem::StackTrace() () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/lib-dynload/../.././libCore.so.6.32
#3  0x00007f649b100f30 in (anonymous namespace)::TExceptionHandlerImp::HandleException(int) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/lib-dynload/../../libcppyy_backend.so
#4  0x00007f649aec4261 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/lib-dynload/../.././libCore.so.6.32
#5  <signal handler called>
#6  0x00007f64783496c7 in TLegend::PaintPrimitives() () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/./libGraf.so.6.32
#7  0x00007f6476bb087e in TPad::Paint(char const*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/./libGpad.so.6.32
#8  0x00007f6476ba45b7 in TPad::Print(char const*, char const*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/./libGpad.so.6.32
#9  0x00007f6476b9a94a in TPad::SaveAs(char const*, char const*) const () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/./libGpad.so.6.32
#10 0x00007f649b101bfe in WrapperCall(long, unsigned long, void*, void*, void*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/lib-dynload/../../libcppyy_backend.so
#11 0x00007f6479342bf6 in CPyCppyy::(anonymous namespace)::VoidExecutor::Execute(long, void*, CPyCppyy::CallContext*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#12 0x00007f64793292fa in CPyCppyy::CPPMethod::ExecuteFast(void*, long, CPyCppyy::CallContext*) [clone .isra.0] () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#13 0x00007f64793294a8 in CPyCppyy::CPPMethod::ExecuteProtected(void*, long, CPyCppyy::CallContext*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#14 0x00007f6479329636 in CPyCppyy::CPPMethod::Execute(void*, long, CPyCppyy::CallContext*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#15 0x00007f64793297a6 in CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object* const*, unsigned long, _object*, CPyCppyy::CallContext*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#16 0x00007f64793317b3 in CPyCppyy::(anonymous namespace)::mp_vectorcall(CPyCppyy::CPPOverload*, _object* const*, unsigned long, _object*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#17 0x000055689353dc9f in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=9223372036854775810, args=0x7f64a90922b8, callable=0x7f635fb41400, tstate=0x5568939ba078 <_PyRuntime+459704>) at /usr/local/src/conda/python-3.12.4/Include/internal/pycore_call.h:92
#18 PyObject_Vectorcall (callable=0x7f635fb41400, args=0x7f64a90922b8, nargsf=9223372036854775810, kwnames=0x0) at /usr/local/src/conda/python-3.12.4/Objects/call.c:325
#19 0x000055689342ff20 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7f64a90920f0, throwflag=<optimized out>) at Python/bytecodes.c:2714
#20 0x00005568935e36fe in PyEval_EvalCode (co=co
entry=0x556893e42020, globals=globals
entry=0x7f64a8f91040, locals=locals
entry=0x7f64a8f91040) at /usr/local/src/conda/python-3.12.4/Python/ceval.c:578
#21 0x00005568936077ba in run_eval_code_obj (tstate=tstate
entry=0x5568939ba078 <_PyRuntime+459704>, co=co
entry=0x556893e42020, globals=globals
entry=0x7f64a8f91040, locals=locals
entry=0x7f64a8f91040) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:1722
#22 0x0000556893602a9b in run_mod (mod=mod
entry=0x556893fdf5d0, filename=filename
entry=0x7f649b54b6f0, globals=globals
entry=0x7f64a8f91040, locals=locals
entry=0x7f64a8f91040, flags=flags
entry=0x7fffff0558f0, arena=arena
entry=0x7f64a8eb3c90) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:1743
#23 0x000055689361b7b0 in pyrun_file (fp=fp
entry=0x556893d8b170, filename=filename
entry=0x7f649b54b6f0, start=start
entry=257, globals=globals
entry=0x7f64a8f91040, locals=locals
entry=0x7f64a8f91040, closeit=closeit
entry=1, flags=0x7fffff0558f0) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:1643
#24 0x000055689361b2fe in _PyRun_SimpleFileObject (fp=0x556893d8b170, filename=0x7f649b54b6f0, closeit=1, flags=0x7fffff0558f0) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:433
#25 0x000055689361aa44 in _PyRun_AnyFileObject (fp=0x556893d8b170, filename=filename
entry=0x7f649b54b6f0, closeit=closeit
entry=1, flags=flags
entry=0x7fffff0558f0) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:78
#26 0x00005568936131e2 in pymain_run_file_obj (skip_source_first_line=0, filename=0x7f649b54b6f0, program_name=0x7f649b500300) at /usr/local/src/conda/python-3.12.4/Modules/main.c:360
#27 pymain_run_file (config=0x55689395cc58 <_PyRuntime+77720>) at /usr/local/src/conda/python-3.12.4/Modules/main.c:379
#28 pymain_run_python (exitcode=0x7fffff0558c4) at /usr/local/src/conda/python-3.12.4/Modules/main.c:629
#29 Py_RunMain () at /usr/local/src/conda/python-3.12.4/Modules/main.c:709
#30 0x00005568935cbfa7 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at /usr/local/src/conda/python-3.12.4/Modules/main.c:763
#31 0x00007f64a8c295d0 in __libc_start_call_main () from /lib64/libc.so.6
#32 0x00007f64a8c29680 in __libc_start_main_impl () from /lib64/libc.so.6
#33 0x00005568935cbe21 in _start ()
===========================================================


The lines below might hint at the cause of the crash. If you see question
marks as part of the stack trace, try to recompile with debugging information
enabled and export CLING_DEBUG=1 environment variable before running.
You may get help by asking at the ROOT forum https://root.cern/forum
preferably using the command (.forum bug) in the ROOT prompt.
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs or (preferably) using the command (.gh bug) in
the ROOT prompt. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007f64783496c7 in TLegend::PaintPrimitives() () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/./libGraf.so.6.32
#7  0x00007f6476bb087e in TPad::Paint(char const*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/./libGpad.so.6.32
#8  0x00007f6476ba45b7 in TPad::Print(char const*, char const*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/./libGpad.so.6.32
#9  0x00007f6476b9a94a in TPad::SaveAs(char const*, char const*) const () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/./libGpad.so.6.32
#10 0x00007f649b101bfe in WrapperCall(long, unsigned long, void*, void*, void*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/lib-dynload/../../libcppyy_backend.so
#11 0x00007f6479342bf6 in CPyCppyy::(anonymous namespace)::VoidExecutor::Execute(long, void*, CPyCppyy::CallContext*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#12 0x00007f64793292fa in CPyCppyy::CPPMethod::ExecuteFast(void*, long, CPyCppyy::CallContext*) [clone .isra.0] () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#13 0x00007f64793294a8 in CPyCppyy::CPPMethod::ExecuteProtected(void*, long, CPyCppyy::CallContext*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#14 0x00007f6479329636 in CPyCppyy::CPPMethod::Execute(void*, long, CPyCppyy::CallContext*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#15 0x00007f64793297a6 in CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object* const*, unsigned long, _object*, CPyCppyy::CallContext*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#16 0x00007f64793317b3 in CPyCppyy::(anonymous namespace)::mp_vectorcall(CPyCppyy::CPPOverload*, _object* const*, unsigned long, _object*) () from /cvmfs/lhcbdev.cern.ch/conda/envs/default/2024-07-10_13-01/linux-64/lib/python3.12/site-packages/libcppyy.so
#17 0x000055689353dc9f in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=9223372036854775810, args=0x7f64a90922b8, callable=0x7f635fb41400, tstate=0x5568939ba078 <_PyRuntime+459704>) at /usr/local/src/conda/python-3.12.4/Include/internal/pycore_call.h:92
#18 PyObject_Vectorcall (callable=0x7f635fb41400, args=0x7f64a90922b8, nargsf=9223372036854775810, kwnames=0x0) at /usr/local/src/conda/python-3.12.4/Objects/call.c:325
#19 0x000055689342ff20 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7f64a90920f0, throwflag=<optimized out>) at Python/bytecodes.c:2714
#20 0x00005568935e36fe in PyEval_EvalCode (co=co
entry=0x556893e42020, globals=globals
entry=0x7f64a8f91040, locals=locals
entry=0x7f64a8f91040) at /usr/local/src/conda/python-3.12.4/Python/ceval.c:578
#21 0x00005568936077ba in run_eval_code_obj (tstate=tstate
entry=0x5568939ba078 <_PyRuntime+459704>, co=co
entry=0x556893e42020, globals=globals
entry=0x7f64a8f91040, locals=locals
entry=0x7f64a8f91040) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:1722
#22 0x0000556893602a9b in run_mod (mod=mod
entry=0x556893fdf5d0, filename=filename
entry=0x7f649b54b6f0, globals=globals
entry=0x7f64a8f91040, locals=locals
entry=0x7f64a8f91040, flags=flags
entry=0x7fffff0558f0, arena=arena
entry=0x7f64a8eb3c90) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:1743
#23 0x000055689361b7b0 in pyrun_file (fp=fp
entry=0x556893d8b170, filename=filename
entry=0x7f649b54b6f0, start=start
entry=257, globals=globals
entry=0x7f64a8f91040, locals=locals
entry=0x7f64a8f91040, closeit=closeit
entry=1, flags=0x7fffff0558f0) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:1643
#24 0x000055689361b2fe in _PyRun_SimpleFileObject (fp=0x556893d8b170, filename=0x7f649b54b6f0, closeit=1, flags=0x7fffff0558f0) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:433
#25 0x000055689361aa44 in _PyRun_AnyFileObject (fp=0x556893d8b170, filename=filename
entry=0x7f649b54b6f0, closeit=closeit
entry=1, flags=flags
entry=0x7fffff0558f0) at /usr/local/src/conda/python-3.12.4/Python/pythonrun.c:78
#26 0x00005568936131e2 in pymain_run_file_obj (skip_source_first_line=0, filename=0x7f649b54b6f0, program_name=0x7f649b500300) at /usr/local/src/conda/python-3.12.4/Modules/main.c:360
#27 pymain_run_file (config=0x55689395cc58 <_PyRuntime+77720>) at /usr/local/src/conda/python-3.12.4/Modules/main.c:379
#28 pymain_run_python (exitcode=0x7fffff0558c4) at /usr/local/src/conda/python-3.12.4/Modules/main.c:629
#29 Py_RunMain () at /usr/local/src/conda/python-3.12.4/Modules/main.c:709
#30 0x00005568935cbfa7 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at /usr/local/src/conda/python-3.12.4/Modules/main.c:763
#31 0x00007f64a8c295d0 in __libc_start_call_main () from /lib64/libc.so.6
#32 0x00007f64a8c29680 in __libc_start_main_impl () from /lib64/libc.so.6
#33 0x00005568935cbe21 in _start ()
===========================================================


Traceback (most recent call last):
  File "/data/bfys/mgalati/RapidSim/scripts/PDFandMC.py", line 659, in <module>
    result = pdf_fit()
             ^^^^^^^^^
  File "/data/bfys/mgalati/RapidSim/scripts/PDFandMC.py", line 445, in pdf_fit
    c.SaveAs(f"{output_now}_NLL.pdf")
cppyy.ll.SegmentationViolation: void TPad::SaveAs(const char* filename = "", Option_t* option = "") =>
    SegmentationViolation: segfault in C++; program state was reset

Any help is very appreciated!


ROOT 6.32.02 Built for linuxx8664gcc on Jul 08 2024, 10:25:47 rom heads/master@tags/v6-32-02


So I found that if I set the limits for x_i using setRange to avoid calculating the nll at 0, the problem occurs when I call draw_sigma_lines:

def draw_sigma_lines(frame, legend, value, err, sigma, color):
            min_val = frame.GetMinimum()
            max_val = frame.GetMaximum()

            for sign in [+1, -1]:
                line = R.TLine(value + sign * sigma * err, min_val, value + sign * sigma * err, max_val)
                line.SetLineColor(color)
                line.SetLineWidth(2)
                line.Draw("same")
            legend.AddEntry(line, f"#pm {sigma}#sigma", "l")

Hi,

What did it change? I understand the code was working and then it stopped.

Best,
D

Hi @mdgalati!

This is one of the classic problems with ROOT about object ownership that you have when using it with Python.

Here, you are creating some TLines in a function, and the Python garbage collector might clean then up at the end of the function. However, the TLegend still points to these deleted TLines, hence the crash.

You need to make sure that none of the objects in the plot get cleaned up before drawing or saving the plot.

In this case, you can achieve this by returning a list containing the TLines, in order to keep them alive:

def draw_sigma_lines(frame, legend, value, err, sigma, color):
            min_val = frame.GetMinimum()
            max_val = frame.GetMaximum()

            lines = []

            for sign in [+1, -1]:
                line = R.TLine(value + sign * sigma * err, min_val, value + sign * sigma * err, max_val)
                line.SetLineColor(color)
                line.SetLineWidth(2)
                line.Draw("same")
                lines.append(line)
            legend.AddEntry(line, f"#pm {sigma}#sigma", "l")

            return lines

        lines_ 1 = draw_sigma_lines(frame, legend, val_i, err_i, 1, R.kCyan + 2)
        lines_2 = draw_sigma_lines(frame, legend, val_i, err_i, 2, R.kMagenta + 2)
1 Like

I believe the problem was that before I didn’t have the plotting of this lines into a function and now I do

That worked! Thank you very much! :pray: