Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROOT crashes with no helpful error messages if a TApplication is not present and tree->StartViewer() is called #6743

Closed
eguiraud opened this issue Nov 2, 2020 · 0 comments · Fixed by #6752
Assignees

Comments

@eguiraud
Copy link
Member

eguiraud commented Nov 2, 2020

Describe the bug

The following reproducer crashes with the stacktrace below (with a debug build of ROOT -- just a segfault for non-debug builds):

#include <TTree.h>
#include <TFile.h>
#include <TApplication.h>

int main()
{
   //TApplication app("app", nullptr, nullptr);
   TFile *outputFile = new TFile("output.root", "RECREATE");

   TTree *tree = new TTree("tree", "treeliberated tree");
   outputFile->Write();

   tree->StartViewer();

   //app.Run();
   outputFile->Close();
}
#8  0x00007fd6cf22b8c2 in TGCompositeFrame::TGCompositeFrame (this=0x56036dc34a10, p=0x0, w=10, h=10, options=3, back=0) at ../../../root_dbg/gui/gui/src/TGFrame.cxx:853
#9  0x00007fd6cf22d4cc in TGMainFrame::TGMainFrame (this=0x56036dc34a10, p=0x0, w=10, h=10, options=2) at ../../../root_dbg/gui/gui/src/TGFrame.cxx:1430
#10 0x00007fd6d64b9a6c in TTreeViewer::TTreeViewer (this=0x56036dc34a10, tree=0x56036d05df80) at ../../../root_dbg/tree/treeviewer/src/TTreeViewer.cxx:349
#11 0x00007fd6d809e059 in ?? ()
#12 0x000056036c1be340 in ?? ()
#13 0x000056036c1be340 in ?? ()
#14 0x000056036dc34a10 in ?? ()
#15 0x000056036dc34a10 in ?? ()
#16 0x00007fff775fd220 in ?? ()
#17 0x00007fff775fd3d8 in ?? ()
#18 0x00007fff775fdc20 in ?? ()
#19 0x00007fff775fd3f8 in ?? ()
#20 0x00000001775fd3e0 in ?? ()
#21 0x0000000000000000 in ?? ()

Expected behavior

The crash is due to a nullptr dereference in TGCompositeFrame::TGCompositeFrame (fParent is null), which in turn is caused by a failed check in TGWindow::TGWindow at TGWindow.cxx:54:

if (!p && gClient) {
   p = gClient->GetRoot();
}

In the condition above, if the user created no TApplication, gClient is false-y.

Rather than crash and burning, we could detect the situation and produce a helpful error message.

Additional context

At least one user could have used a better error message 😄

@bellenot bellenot assigned bellenot and unassigned bellenot Nov 2, 2020
bellenot added a commit to bellenot/root that referenced this issue Nov 4, 2020
Should fix ROOT crashes with no helpful error messages if a TApplication is not present and tree->StartViewer() is called. Now it prints the following warning:
```
Warning in <TTreePlayer::StartViewer>: The tree viewer cannot run in batch mode
```
bellenot added a commit that referenced this issue Nov 5, 2020
…e->StartViewer() is called (#6752)

* Fix Github issue #6743

Should fix ROOT crashes with no helpful error messages if a TApplication is not present and tree->StartViewer() is called. Now it prints the following warning:
```
Warning in <TTreePlayer::StartViewer>: The tree viewer cannot run in batch mode
```

* Use `gSystem->Exit()` instead of `std::exit()` as suggested by Philippe
vgvassilev pushed a commit to vgvassilev/root that referenced this issue Nov 12, 2020
…sent and tree->StartViewer() is called (root-project#6752)

* Fix Github issue root-project#6743

Should fix ROOT crashes with no helpful error messages if a TApplication is not present and tree->StartViewer() is called. Now it prints the following warning:
```
Warning in <TTreePlayer::StartViewer>: The tree viewer cannot run in batch mode
```

* Use `gSystem->Exit()` instead of `std::exit()` as suggested by Philippe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants