I am trying to compile a program based on macro.C (attached to this message); what I am trying to do is to write the classes into separate files, not in the main program like macro.C and get an executable. The program compiles without a problem but when I try to open it (./task1) I get ***Break**** Segmentation violation. The main body of the program is task1.C.
I was not able to reproduce this in my environment with gcc-4.8.5 (CentOS 7) and ROOT v6-22-02.
What I can suggest is to add the -g compiler option to your command line, and running your program under gdb so that you are able to get a backtrace when the program SIGSEGV’s. Please, attach the generated backtrace so that we can diagnose the problem.
When I comment lines 58 to 62 from task1.C the program works well and I can visualize the data with TBrowser. But when I uncomment those lines, tree -> StartViewer() gives me a segmentation fault. Here is the error:
>*** Break *** segmentation violation
>
>
>
>===========================================================
>There was a crash.
>This is the entire stack trace of all threads:
>===========================================================
>#0 0x00007f100c8f6dba in __GI___wait4 (pid=10206, stat_loc=stat_loc
>entry=0x7ffe5be9d8e8, options=options
>entry=0, usage=usage
>entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
>#1 0x00007f100c8f6d7b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
>entry=0x7ffe5be9d8e8, options=options
>entry=0) at waitpid.c:38
>#2 0x00007f100c8660e7 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
>#3 0x00007f100d90f49e in TUnixSystem::StackTrace() () from /home/petre/ROOT/lib/libCore.so.6.22
>#4 0x00007f100d90c325 in TUnixSystem::DispatchSignals(ESignals) () from /home/petre/ROOT/lib/libCore.so.6.22
>#5 <signal handler called>
>#6 0x0000561a1690bb57 in main () at task1.C:58
>===========================================================
>
>
>The lines below might hint at the cause of the crash.
>You may get help by asking at the ROOT forum http://root.cern.ch/forum
>Only if you are really convinced it is a bug in ROOT then please submit a
>report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
>from above as an attachment in addition to anything else
>that might help us fixing this issue.
>===========================================================
>#6 0x0000561a1690bb57 in main () at task1.C:58
>===========================================================
Lacking a ROOT debug build where I can inspect the complete backtrace, I will invite @jblomer and @eguiraud. Maybe they can help diagnosing this issue.
The macro works well. The problem appears when I compile the program and I run it (when I run ./task1). I don’t understand why this happens since the macro works without issues.
Hi,
the stacktrace mentions task1.C:58 as the offending line.
At that line there is
tree->StartViewer();
but right before you close the file that contains tree, outputFile->Close: as a consequence, the TTree object tree points to is destroyed. Classic ROOT ownership shenanigans.
Moving outputFile->Close(); to the end of main should fix the issue.
Alright: to fix the TGCompositeFrame crash, you need to have a TApplication running, as mentioned above in the thread (it’s always needed to have ROOT graphics properly working in compiled ROOT programs).
You need to:
#include "TApplication.h"
add TApplication app("app", nullptr, nullptr); at the beginning of main
add app.Run() at the end of main, before outputfile->Close()
The attached version of task1.C compiles and runs fine for me.