Error when drawing a canvas in root file

Hello.
I create TCanvas with a TGraph and write it into a root file:

TFile file("filename.root", "recreate");
TCanvas canvas("canvas", "", 1920, 1080);
TGraph graph;
graph.SetNameTitle("zenith", "zenith");
canvas.Divide(2, 2);
canvas.cd(1);
graph.Draw("AC*");
canvas.Update();
canvas.Write();

If I use it in a ROOT macro script, everything is ok.
But if I do it in compiled program then I can’t draw this canvas in the ROOT interpreter because of errors:

root [2] canvas->Draw()

*** Break *** segmentation violation

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCore.so] TList::FindObject(char const*) const (no debug info)

[/Users/bair/Projects/root/root_install/lib/libGpad.so] TPad::FindObject(char const*) const (no debug info)

[/Users/bair/Projects/root/root_install/lib/libGpad.so] TPad::FindObject(char const*) const (no debug info)

[/Users/bair/Projects/root/root_install/lib/libGpad.so] TPad::UseCurrentStyle() (no debug info)

[/Users/bair/Projects/root/root_install/lib/libGpad.so] TCanvas::UseCurrentStyle() (no debug info)

[/Users/bair/Projects/root/root_install/lib/libRIO.so] TKey::ReadObj() (no debug info)

[/Users/bair/Projects/root/root_install/lib/libRIO.so] TDirectoryFile::Get(char const*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCore.so] TROOT::FindSpecialObject(char const*, void*&) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] TCling::GetObjectAddress(char const*, void*&) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] TClingCallbacks::tryFindROOTSpecialInternal(clang::LookupResult&, clang::Scope*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] TClingCallbacks::LookupObject(clang::LookupResult&, clang::Scope*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] cling::MultiplexInterpreterCallbacks::LookupObject(clang::LookupResult&, clang::Scope*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::MultiplexExternalSemaSource::LookupUnqualified(clang::LookupResult&, clang::Scope*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Sema::ClassifyName(clang::Scope*, clang::CXXScopeSpec&, clang::IdentifierInfo*&, clang::SourceLocation, clang::Token const&, clang::CorrectionCandidateCallback*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::TryAnnotateName(clang::CorrectionCandidateCallback*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributesWithRange&) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseCompoundStatementBody(bool) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] cling::IncrementalParser::ParseInternal(llvm::StringRef) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] cling::Interpreter::process(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, cling::Value*, cling::Transaction**, bool) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libRint.so] TRint::HandleTermInput() (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCore.so] TUnixSystem::CheckDescriptors() (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCore.so] TSystem::InnerLoop() (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCore.so] TSystem::Run() (no debug info)

[/Users/bair/Projects/root/root_install/lib/libCore.so] TApplication::Run(bool) (no debug info)

[/Users/bair/Projects/root/root_install/lib/libRint.so] TRint::Run(bool) (no debug info)

[/Users/bair/Projects/root/root_install/bin/root.exe] main (no debug info)

[/usr/lib/dyld] start (no debug info)

If I remove the line: graph.SetNameTitle("zenith", "zenith»); it works again.
It’s strange behaviour, why don’t I change name of the graph (I want to use the graph name in the interpreter)?

Thanks,
Bair

ROOT Version: 6.30/02
Platform: MacOS
Compiler: clang 15.0.0


Welcome to the ROOT forum,

What are you doing exactly to compile this script ? Can you post here the exact set of commands you are using ?

I compiled it as a C++ program with:

g++ -I/Users/bair/Projects/root/root_install/include -pthread -std=c++17 -m64 -Wall -Winit-self -fPIC -Wpointer-arith -Woverloaded-virtual -g -fcolor-diagnostics -std=c++17 -L/Users/bair/Projects/root/root_install/lib -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -Wl,-rpath,/Users/bair/Projects/root/root_install/lib -stdlib=libc++ -lpthread -lm -ldl check.cc -o ch

Can you also provide check.cc ?

#include <TFile.h>
#include "TGraph.h"
#include "TCanvas.h"

int main(int argc, char** argv )
{
    TFile file("filename.root", "recreate");

    TCanvas canvas("canvas", "", 1920, 1080);
    TGraph graph;
    graph.SetNameTitle("zenith", "zenith");    

    auto n = graph.GetN();
    graph.SetPoint(n, 0, 1);

    canvas.Divide(2, 2);
    canvas.cd(1);
    graph.Draw("AC*");

    canvas.Update();
    canvas.Write();
    file.Close();

    return 0;
}

It worked for me:

% g++ check.cc $(root-config --glibs --cflags --libs) -o check
% ./check

then:

% root filename.root                                            
root [0] 
Attaching file filename.root as _file0...
(TFile *) 0x7fa78709c900
root [1] canvas->Draw()
root [2] 

I’ve just checked on Mac and linux machines and have the same error.
Both have ROOT Version: 6.30/02.

Have you done it with this version?

I don’t have any idea what I’m doing wrong.

I did it with ROOT master

I’ve done the same with ROOT 6.32.04 and it’s working properly now.
Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.