TApplication::Terminate() crashes the program!

Dear root experts,
I’m running on a Mac OS Lion a C++ compiled code with root.
In the main I do:
TApplication* theApp = new TApplication(“Applications”, &argc, argv);
.
.
.
at the end of the main I do:
theApp->Terminate(0);
return 0;

At the instruction theApp->Terminate(0); the program crashes !!!
Can you please help me to make the program ending without crashing ?
Thanks,

  • Mauro.
1 Like

[quote=“mauroroot”]Can you please help me to make the program ending without crashing ?[/quote] Don’t call TApplication::Terminate, just “return 0;”. :mrgreen:

Thanks for you answer Wile,
but the program is still crashing even with your suggestion.

One more piece of information: I’m also using ROOFIT in my program.
( maybe this can help the experts to to have a more clear picture of the problem )

The output of the crashing is at the bottom of this message.

Many thanks.

  • Mauro.

*** Break *** segmentation violation

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

Thread 1 (process 57725):
#0 0x00007fff8b397168 in wait4 ()
#1 0x00007fff903935f5 in system ()
#2 0x000000010f196b16 in TUnixSystem::StackTrace ()
#3 0x000000010f1948a7 in TUnixSystem::DispatchSignals ()
#4
#5 0x000000010f14eaf5 in TList::Delete ()
#6 0x0000000111ed25d7 in RooPlot::~RooPlot ()
#7 0x0000000111ed24f2 in RooPlot::~RooPlot ()
#8 0x000000010f14b0b4 in TCollection::GarbageCollect ()
#9 0x000000010f14c951 in THashList::Delete ()
#10 0x00000001100b20d4 in TDirectoryFile::Close ()
#11 0x00000001100bd1e2 in TFile::Close ()
#12 0x00000001100bbc96 in TFile::~TFile ()
#13 0x00000001100bbc32 in TFile::~TFile ()
#14 0x000000010f14b0b4 in TCollection::GarbageCollect ()
#15 0x000000010f14e9cd in TList::Delete ()
#16 0x000000010f10385e in TROOT::~TROOT ()
#17 0x00007fff903d07c8 in __cxa_finalize ()
#18 0x00007fff903d0652 in exit ()
#19 0x000000010e6aaaab in start ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
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.

#5 0x000000010f14eaf5 in TList::Delete ()
#6 0x0000000111ed25d7 in RooPlot::~RooPlot ()
#7 0x0000000111ed24f2 in RooPlot::~RooPlot ()
#8 0x000000010f14b0b4 in TCollection::GarbageCollect ()
#9 0x000000010f14c951 in THashList::Delete ()
#10 0x00000001100b20d4 in TDirectoryFile::Close ()
#11 0x00000001100bd1e2 in TFile::Close ()
#12 0x00000001100bbc96 in TFile::~TFile ()
#13 0x00000001100bbc32 in TFile::~TFile ()
#14 0x000000010f14b0b4 in TCollection::GarbageCollect ()
#15 0x000000010f14e9cd in TList::Delete ()
#16 0x000000010f10385e in TROOT::~TROOT ()
#17 0x00007fff903d07c8 in __cxa_finalize ()
#18 0x00007fff903d0652 in exit ()
#19 0x000000010e6aaaab in start ()

Maybe you should report your ROOT version and your compiler version.

Hi Wile,

  • my ROOT version is: 5.32/01
  • my compiler version is: i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
  • my MAC OS X version is: 10.7.5

Many thanks for your support.

  • Mauro.

Well, I hate to say it … but … a typical reply here will be … can you try the newest v5-34-00-patches branch :-&
BTW. if it’s really a “RooFit” issue, you’ll probably get help faster on the Stat and Math Tool Support forum.

Hi Wile,
done ! I’ve also tried with root v5-34-02 and the problem remains

I’ve posted the same problem also in the Stat and Math Tool Support forum as you suggested

Many thanks for your help

  • Mauro

Hi Mauro,

Make sure to delete/close all the TFile before returning/calling Terminate?

Cheers,
Philippe.

Hi All,
I nailed down the problem and it comes from the “TPaveText” !!!
Please have a look at the Test.cc program in attachment.

Try comment/uncomment the line:

paveTextX->SetFillColor(kWhite);

And you can see that one of the two cases the program crashes when “Terminate” is called.
Do you have any suggestion on how to fix this ?

Thanks,

Hi,

You can try calling:gROOT->CloseFiles();just before Terminate. If this does not solve the problem, then you ought to run with valgrind to see if there is a double delete or memory overwrite.

Philippe.

Hi Philippe,
thanks, but it still doesn’t work.

Thanks any way !

  • Mauro.

Hi,

Humm … does it fail differently (it can not fail the same or we are missing something essential)? Did you try valgrind? Can you provide a complete running example?

Philippe.

Hi Philippe,
I have never used valgrind. Sorry.

I guess you can test it yourself with the Test.cc code I’ve provided in attachment :

  • I simply took a ROOFit example code from: root.cern.ch/root/html/tutorials … index.html
  • I added a main
  • Within the main I instantiate a TApplication
  • I call the ROOFit code ( in the ROOFit code I added a couple of instructions related to TPaveText )
  • Then I Terminate it
    That’s all.

Commenting / uncommenting the lines related to TPaveText, the code doesn’t / does crash.

Thanks,

  • Mauro.
  1. Do ALWAYS make sure that a pointer is NON-NULL, before you try to use it:
  1. You MUST NOT “delete paveTextX;” when it is still used somewhere (e.g. it’s drawn in the canvas).

  2. Honestly speaking, I don’t think “theApp->Terminate(0);” should be there (it can be used in a GUI, with use of the signal/slot mechanism, to terminate the application). But Philippe might bring more light in here.

[quote]3. Honestly speaking, I don’t think “theApp->Terminate(0);” should be there (it can be used in a GUI, with use of the signal/slot mechanism, to terminate the application). But Philippe might bring more light in here.[/quote]That’s correct. However it should also not be a factor in this example working or not …

Philippe.

[quote=“pcanal”]That’s correct. However it should also not be a factor in this example working or not …[/quote] It isn’t. His “paveTextX” pointer is null.