Invalid Memory Pointer Issue When Creating Plots

I’m using a pre-packaged piece of code to plot graphs for data on interaction rates that I have. The code should output three canvases but at the moment only one of the plots is being produced before an error occurs:

**warning:** **invalid memory pointer passed to a callee:**


The line in the code that the error points to is located here:

    gr = (TGraph*)f.Get(graphname);

Funnily enough this code worked a couple of months ago. Since then I have reinstalled newer versions of root and Xcode so I’m not sure if that has anything to do with it. gr->SetLineWidth also appears earlier in the code and seems to work for the first plot. Any help would be greatly appreciated!


ROOT Version: 6-22-00
Platform: MacOS Catalina
Compiler: Not Provided

Hi Robert,

can you make sure your TGraph was indeed fetched from the file:

gr = (TGraph*)f.Get(graphname);
if (!gr)
    printf("ERROR: can't fetch TGraph from TFile\n");

Hi Yus, thanks for your reply.

I put your code in and it made no difference to the error message that comes up. Not sure if it’s useful but here are all the lines subsequent to the error message itself:

[/Users/robertsmith/Documents/rootbuild/lib/] cling_runtime_internal_throwIfInvalidPointer (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] 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/robertsmith/Documents/rootbuild/lib/] 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/robertsmith/Documents/rootbuild/lib/] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TRint::HandleTermInput() (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TUnixSystem::CheckDescriptors() (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TSystem::InnerLoop() (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TSystem::Run() (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TApplication::Run(bool) (no debug info)
[/Users/robertsmith/Documents/rootbuild/lib/] TRint::Run(bool) (no debug info)
[/Users/robertsmith/Documents/rootbuild/bin/root.exe] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)
Error in <HandleInterpreterException>: Trying to access a pointer that points to an invalid memory address..
Execution of your code was aborted.
/Users/robertsmith/Documents/Project/software/snowglobes/plots/plot_event_rates.C:236:6: warning: invalid memory pointer passed to a callee:

That’s weird. I was able to reproduce the exact same error message (the stack trace and then

Error in <HandleInterpreterException>: Trying to access a pointer that points to an invalid memory address..
Execution of your code was aborted.
ROOT_prompt_2:1:1: warning: invalid memory pointer passed to a callee:

) when opening a file and then fetching a TGraph out of it which just isn’t there. I guess I need a small reproducer to help out more.

I managed to fix it. The graph it was trying to get indeed wasn’t there when it should have been. I had to change some code in the file that makes the graphs.

Thanks a lot for your help!