Different behaviour between macros and compilad gui app

Describe the bug

I am writing custom GUI app with event viewer. The code is WIP but the current source can be found here (MWE on the end of the post): sabat-framework/tools/event_display.C at 97e1170fb8c2bd2b535598ee0215d98b71d85f90 · rlalik/sabat-framework · GitHub

The code can be run as a macro, or as a standalone application. When compiling application, I compile is a normal release type, and also with sanitizers enabled. SO three different modes, and only works properly (sanitizers mode) and two other have different issues.

To make quick summary, I have a class event_viewer which defines private members l_evt and l_all which are text labels to store the event number later and a variable event_id storing the current event number. There are two buttons Prev/Next which are used to change to the previous/next event. These button call slots Prev()/Next(). The slots later call common function load_event(). The essence of the code is below.

class event_viewer : public TObject
{
    RQ_OBJECT("event_viewer")

    long long event_id {0};             ///< Current event id.
    TGLabel* l_evt {nullptr};           ///< Displays current event number
    TGLabel* l_all {nullptr};           ///< Displays all events number

    event_viewer(const char* file,
                 const char* ascii_params = "sabat_params.txt",
                 const char* sabat_geometry = "sabat_geometry.root")
        : TObject()
    {
        // some other code here
        make_gui();
    }

    void make_gui()
    {
        // some code here
        TGTextButton* b = nullptr;

        // navigation button Prev
        b = new TGTextButton(group_navi, "&Prev");
        group_navi->AddFrame(b, new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 0));
        b->Connect("Clicked()", "event_viewer", this, "Prev()");

        // some other code here
        // these labels are going to be updated after each Prev/Next action
        TGHorizontalFrame* group_event_current = new TGHorizontalFrame(group_event_info);

        l_evt = new TGLabel(nullptr, "        ");
        group_event_current->AddFrame(l_evt, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 5, 0));

        TGHorizontalFrame* group_event_all = new TGHorizontalFrame(group_event_info);

        l_all = new TGLabel(nullptr, "        ");
        group_event_all->AddFrame(l_all, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 5, 0));

        group_event_info->AddFrame(group_event_current, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
        group_event_info->AddFrame(group_event_all, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));

        group_navi->AddFrame(group_event_info, new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 0));

        // some other code here
        // navigation button Next
        b = new TGTextButton(group_navi, "&Next");
        group_navi->AddFrame(b, new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 0));
        b->Connect("Clicked()", "event_viewer", this, "Next()");

        // some other code here
    }

    auto Next() -> void
    {
        std::print("[{:s}]  At event: {:d} of {:d} total.\n", __PRETTY_FUNCTION__, event_id, reader.get_entries() - 1);

        if (event_id == reader.get_entries() - 1) {
            std::print("Already at the last event: {:d} of {:d}.\n", event_id, reader.get_entries() - 1);
        } else {
            ++(event_id);
            load_event();
        }
    }

    auto Prev() -> void
    {
        std::print("[{:s}]  At event: {:d} of {:d} total.\n", __PRETTY_FUNCTION__, event_id, reader.get_entries() - 1);

        if (event_id == 0) {
            std::print("Already at the first event: {:d} of {:d}.\n", event_id, reader.get_entries() - 1);
        } else {
            --(event_id);
            load_event();
        }
    }

    void load_event()
    {
        std::print("[{:s}]  this: {:p}   l_evt: {:p} l_all: {:p}  event: {:d}\n",
                   __PRETTY_FUNCTION__,
                   (void*)this,
                   (void*)l_evt,
                   (void*)l_all,
                   event_id);

        l_evt->SetText(TString::Format("%5lld", event_id).Data());
        l_all->SetText(TString::Format("%5lld", reader.get_entries()).Data());
    }

First case - macro

Now, when running the code as a macro:

root output_sabat_run11.root event_display.C+
root [0] 
Attaching file /home/rafal/sabat/src/sabat-framework/build/default/output_sabat_run11.root as _file0...
(TFile *) 0x55700c1e98b0
Processing event_display.C+...
Info in <TUnixSystem::ACLiC>: creating shared library /home/rafal/sabat/src/sabat-framework/tools/./event_display_C.so
[*** LOG ERROR #0001 ***] [2025-10-21 13:05:00] [] std::bad_alloc
Fontconfig warning: using without calling FcInit()
Warning in <TASImage::GetMask>: No image

This is first part - there is some LOG error std::bad_alloc which I have no idea where it come from. Does it looks like something from ROOT? I also use libraries liek spdlog. Below is the next part of the startup procedure which is OK. I print values of this (address of the event_viewer class) and content (addresses) of the l_evt and l_all variables.

void event_viewer::ObstaclePropHandler::AlphaChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7fff6d8b2f80   l_evt: 0x7f7914db1830 l_all: 0x7f7914db20a0  event: 0
void event_viewer::ObstaclePropHandler::AlphaChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7fff6d8b2f80   l_evt: 0x7f7914db1830 l_all: 0x7f7914db20a0  event: 0
void event_viewer::ObstaclePropHandler::ScaleChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7fff6d8b2f80   l_evt: 0x7f7914db1830 l_all: 0x7f7914db20a0  event: 0

At this stage, I click the Next button in the GUI:


which results in this (see below). The event_id gest crazy, this stays the same but both l_evt and l_all change their content. And of course crash and long output.

root [2] [void event_viewer::Next()]  At event: 140158017786272 of -1 total.
[void event_viewer::load_event()]  this: 0x7fff6d8b2f80   l_evt: 0x7f79150b4d70 l_all: 0x0  event: 140158017786273

 *** Break *** segmentation violation



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

Thread 1 (Thread 0x7f794c80aac0 (LWP 16147) "root.exe"):
#0  0x00007f794ca9c172 in ?? () from /usr/lib64/libc.so.6
#1  0x00007f794ca904cf in ?? () from /usr/lib64/libc.so.6
#2  0x00007f794ca90511 in ?? () from /usr/lib64/libc.so.6
#3  0x00007f794cb01b3b in wait4 () from /usr/lib64/libc.so.6
#4  0x00007f794ca509fd in ?? () from /usr/lib64/libc.so.6
#5  0x00007f794d31c365 in TUnixSystem::StackTrace() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#6  0x00007f794d31bce8 in TUnixSystem::DispatchSignals(ESignals) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#7  <signal handler called>
#8  0x0000000000000094 in ?? ()
#9  0x00007f7935b9f42a in event_viewer::load_event() () from /home/rafal/sabat/src/sabat-framework/tools/event_display_C.so
#10 0x00007f7931e880ff in ?? ()
#11 0x00007f7914dcd1a0 in ?? ()
#12 0x00007f7931e88110 in ?? ()
#13 0x00007fff6d8b31c8 in ?? ()
#14 0x00007fff6d8b2f80 in ?? ()
#15 0x00007fff6d8b3218 in ?? ()
#16 0xffffffffffffffff in ?? ()
#17 0x00007fff6d8b42f0 in ?? ()
#18 0x00007f7945da6c15 in TClingCallFunc::exec(void*, void*) () from /home/rafal/projects/cern/install/root_23/lib/libCling.so
===========================================================


The lines below might hint at the cause of the crash. If you see question
marks as part of the stack trace, try to recompile with debugging information
enabled and export CLING_DEBUG=1 environment variable before running.
You may get help by asking at the ROOT forum https://root.cern/forum
preferably using the command (.forum bug) in the ROOT prompt.
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs or (preferably) using the command (.gh bug) in
the ROOT prompt. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#8  0x0000000000000094 in ?? ()
#9  0x00007f7935b9f42a in event_viewer::load_event() () from /home/rafal/sabat/src/sabat-framework/tools/event_display_C.so
#10 0x00007f7931e880ff in ?? ()
#11 0x00007f7914dcd1a0 in ?? ()
#12 0x00007f7931e88110 in ?? ()
#13 0x00007fff6d8b31c8 in ?? ()
#14 0x00007fff6d8b2f80 in ?? ()
#15 0x00007fff6d8b3218 in ?? ()
#16 0xffffffffffffffff in ?? ()
#17 0x00007fff6d8b42f0 in ?? ()
#18 0x00007f7945da6c15 in TClingCallFunc::exec(void*, void*) () from /home/rafal/projects/cern/install/root_23/lib/libCling.so
===========================================================


Root > .q

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f794ca9c172 in ?? () from /usr/lib64/libc.so.6
#1  0x00007f794ca904cf in ?? () from /usr/lib64/libc.so.6
#2  0x00007f794ca90511 in ?? () from /usr/lib64/libc.so.6
#3  0x00007f794cb01b3b in wait4 () from /usr/lib64/libc.so.6
#4  0x00007f794ca509fd in ?? () from /usr/lib64/libc.so.6
#5  0x00007f794d31c365 in TUnixSystem::StackTrace() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#6  0x00007f794d31bce8 in TUnixSystem::DispatchSignals(ESignals) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#7  <signal handler called>
#8  0x00007f794d24ad3a in THashList::RecursiveRemove(TObject*) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#9  0x00007f794d1e9eb7 in TROOT::RecursiveRemove(TObject*) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#10 0x00007f794d1cd354 in TNamed::~TNamed() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#11 0x00007f794d21c882 in TSystemDirectory::~TSystemDirectory() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#12 0x00007f794d250859 in TList::Clear(char const*) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#13 0x00007f794d250a86 in TList::~TList() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#14 0x00007f794d250c22 in TList::~TList() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#15 0x00007f794d1ebb69 in TROOT::~TROOT() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#16 0x00007f794ca3e5b1 in ?? () from /usr/lib64/libc.so.6
#17 0x00007f794ca3e690 in exit () from /usr/lib64/libc.so.6
#18 0x00007f794d312cbf in TUnixSystem::Exit(int, bool) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#19 0x00007f794d1922e7 in TApplication::Terminate(int) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#20 0x00007f794d19386e in TApplication::ProcessLine(char const*, bool, int*) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#21 0x00007f794d4cf8b9 in TRint::ProcessLineNr(char const*, char const*, int*) () from /home/rafal/projects/cern/install/root_23/lib/libRint.so.6.37
#22 0x00007f794d4cfd51 in TRint::HandleTermInput() () from /home/rafal/projects/cern/install/root_23/lib/libRint.so.6.37
#23 0x00007f794d3185de in TUnixSystem::CheckDescriptors() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#24 0x00007f794d31ba88 in TUnixSystem::DispatchOneEvent(bool) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#25 0x00007f794d209f94 in TSystem::Run() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#26 0x00007f794d18ecb7 in TApplication::Run(bool) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#27 0x00007f794d4d0dc3 in TRint::Run(bool) () from /home/rafal/projects/cern/install/root_23/lib/libRint.so.6.37
#28 0x0000556fd4d6c303 in main ()
===========================================================


The lines below might hint at the cause of the crash. If you see question
marks as part of the stack trace, try to recompile with debugging information
enabled and export CLING_DEBUG=1 environment variable before running.
You may get help by asking at the ROOT forum https://root.cern/forum
preferably using the command (.forum bug) in the ROOT prompt.
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs or (preferably) using the command (.gh bug) in
the ROOT prompt. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#8  0x00007f794d24ad3a in THashList::RecursiveRemove(TObject*) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#9  0x00007f794d1e9eb7 in TROOT::RecursiveRemove(TObject*) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#10 0x00007f794d1cd354 in TNamed::~TNamed() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#11 0x00007f794d21c882 in TSystemDirectory::~TSystemDirectory() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#12 0x00007f794d250859 in TList::Clear(char const*) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#13 0x00007f794d250a86 in TList::~TList() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#14 0x00007f794d250c22 in TList::~TList() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#15 0x00007f794d1ebb69 in TROOT::~TROOT() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#16 0x00007f794ca3e5b1 in ?? () from /usr/lib64/libc.so.6
#17 0x00007f794ca3e690 in exit () from /usr/lib64/libc.so.6
#18 0x00007f794d312cbf in TUnixSystem::Exit(int, bool) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#19 0x00007f794d1922e7 in TApplication::Terminate(int) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
===========================================================

Second case, compiled aplication:

  1. Start:
./sabat-viewer output_sabat_run11.root
Args:: input file: output_sabat_run11.root  ascii pars: sabat_pars.txt  geom file: sabat_geometry.root
Fontconfig warning: using without calling FcInit()
Warning in <TASImage::GetMask>: No image
void event_viewer::ObstaclePropHandler::AlphaChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7ffd60093250   l_evt: 0x557df432a9c0 l_all: 0x557df432ce40  event: 0
void event_viewer::ObstaclePropHandler::AlphaChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7ffd60093250   l_evt: 0x557df432a9c0 l_all: 0x557df432ce40  event: 0
void event_viewer::ObstaclePropHandler::ScaleChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7ffd60093250   l_evt: 0x557df432a9c0 l_all: 0x557df432ce40  event: 0
  1. Button action, both _evt and l_all change their value.
[void event_viewer::Next()]  At event: 0 of 68895 total.
[void event_viewer::load_event()]  this: 0x7ffd60093250   l_evt: 0x7ffd600936e0 l_all: 0x557de6927460  event: 1

 *** Break *** segmentation violation



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

Thread 1 (Thread 0x7f3b956afe80 (LWP 19812) "sabat-viewer"):
#0  0x00007f3b96124172 in ?? () from /usr/lib64/libc.so.6
#1  0x00007f3b961184cf in ?? () from /usr/lib64/libc.so.6
#2  0x00007f3b96118511 in ?? () from /usr/lib64/libc.so.6
#3  0x00007f3b96189b3b in wait4 () from /usr/lib64/libc.so.6
#4  0x00007f3b960d89fd in ?? () from /usr/lib64/libc.so.6
#5  0x00007f3b98591365 in TUnixSystem::StackTrace() () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#6  0x00007f3b98590ce8 in TUnixSystem::DispatchSignals(ESignals) () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#7  <signal handler called>
#8  0x00007f3b6c03b607 in ?? ()
#9  0x0000557df762f780 in ?? ()
#10 0x00007ffd600936e0 in ?? ()
#11 0x00007ffd60092f28 in ?? ()
#12 0x0000557df1359280 in ?? ()
#13 0x00007ffd60092fc0 in ?? ()
#14 0x00007f3b6c03b30a in ?? ()
#15 0x00007ffd600934e8 in ?? ()
#16 0x715b0a36253f0000 in ?? ()
#17 0x00007ffd600936e0 in ?? ()
#18 0x0000557de6927460 in ?? ()
#19 0x0000557df762f780 in ?? ()
#20 0x00007f3b6c03b5a0 in ?? ()
#21 0x00007ffd60092f90 in ?? ()
#22 0x00007f3b98470610 in ?? () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#23 0x00007ffd600936e0 in ?? ()
#24 0x00007f3b6c03b5c0 in ?? ()
#25 0x0000000000010d1f in ?? ()
#26 0x00007f3b8f266604 in cling::Interpreter::DeclareCFunction(llvm::StringRef, llvm::StringRef, bool, cling::Transaction*&) () from /home/rafal/projects/cern/install/root_23/lib/libCling.so
#27 0x0000000000010d1f in ?? ()
#28 0x00007ffd60093110 in ?? ()
#29 0x00007f3b8f1b1c15 in TClingCallFunc::exec(void*, void*) () from /home/rafal/projects/cern/install/root_23/lib/libCling.so
===========================================================


The lines below might hint at the cause of the crash. If you see question
marks as part of the stack trace, try to recompile with debugging information
enabled and export CLING_DEBUG=1 environment variable before running.
You may get help by asking at the ROOT forum https://root.cern/forum
preferably using the command (.forum bug) in the ROOT prompt.
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs or (preferably) using the command (.gh bug) in
the ROOT prompt. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#8  0x00007f3b6c03b607 in ?? ()
#9  0x0000557df762f780 in ?? ()
#10 0x00007ffd600936e0 in ?? ()
#11 0x00007ffd60092f28 in ?? ()
#12 0x0000557df1359280 in ?? ()
#13 0x00007ffd60092fc0 in ?? ()
#14 0x00007f3b6c03b30a in ?? ()
#15 0x00007ffd600934e8 in ?? ()
#16 0x715b0a36253f0000 in ?? ()
#17 0x00007ffd600936e0 in ?? ()
#18 0x0000557de6927460 in ?? ()
#19 0x0000557df762f780 in ?? ()
#20 0x00007f3b6c03b5a0 in ?? ()
#21 0x00007ffd60092f90 in ?? ()
#22 0x00007f3b98470610 in ?? () from /home/rafal/projects/cern/install/root_23/lib/libCore.so.6.37
#23 0x00007ffd600936e0 in ?? ()
#24 0x00007f3b6c03b5c0 in ?? ()
#25 0x0000000000010d1f in ?? ()
#26 0x00007f3b8f266604 in cling::Interpreter::DeclareCFunction(llvm::StringRef, llvm::StringRef, bool, cling::Transaction*&) () from /home/rafal/projects/cern/install/root_23/lib/libCling.so
#27 0x0000000000010d1f in ?? ()
#28 0x00007ffd60093110 in ?? ()
#29 0x00007f3b8f1b1c15 in TClingCallFunc::exec(void*, void*) () from /home/rafal/projects/cern/install/root_23/lib/libCling.so
===========================================================

The third case - standalone app compield with sanitizers:

  1. Startup
./sabat-viewer output_sabat_run11.root 
Args:: input file: output_sabat_run11.root  ascii pars: sabat_pars.txt  geom file: sabat_geometry.root
Fontconfig warning: using without calling FcInit()
Warning in <TASImage::GetMask>: No image
void event_viewer::ObstaclePropHandler::AlphaChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 0
void event_viewer::ObstaclePropHandler::AlphaChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 0
void event_viewer::ObstaclePropHandler::ScaleChanged(Int_t)
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 0
  1. Button action - is OK
[void event_viewer::Next()]  At event: 0 of 68895 total.
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 1
[void event_viewer::Next()]  At event: 1 of 68895 total.
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 2
[void event_viewer::Next()]  At event: 2 of 68895 total.
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 3
[void event_viewer::Next()]  At event: 3 of 68895 total.
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 4
[void event_viewer::Prev()]  At event: 4 of 68895 total.
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 3
[void event_viewer::Prev()]  At event: 3 of 68895 total.
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 2
[void event_viewer::Prev()]  At event: 2 of 68895 total.
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 1
[void event_viewer::Prev()]  At event: 1 of 68895 total.
[void event_viewer::load_event()]  this: 0x7b79617f1140   l_evt: 0x7c996260e0c0 l_all: 0x7c996260e3c0  event: 0
[void event_viewer::Prev()]  At event: 0 of 68895 total.
Already at the first event: 0 of 68895.
[void event_viewer::Prev()]  At event: 0 of 68895 total.
Already at the first event: 0 of 68895.

Any ideas what is happening in this code? Why the l_evt and l_all pointers and event_id variable are changing? I was expecting some buffer overflows, so that is why I tried with sanitizers, but apparently this is the only working version.

MWE

Here is the script which I run after removing some minor deps like spdlog and spark+sabat dependency (framework libraries).

event_display.C (28.3 KB)

To compile also requires this:
SabatViewerLinkDef.h (131 Bytes)

I use cmake to make binaries:

file(TOUCH ${CMAKE_BINARY_DIR}/empty.C)
add_executable(sabat_viewer_exe ${CMAKE_BINARY_DIR}/empty.C)

ROOT_GENERATE_DICTIONARY(G__sabat_viewer_cc
    event_display.C
    MODULE sabat_viewer_exe
    LINKDEF SabatViewerLinkDef.h
    NO_CXXMODULE
)

add_executable(sabat::sabat_viewer ALIAS sabat_viewer_exe)

set_property(TARGET sabat_viewer_exe PROPERTY OUTPUT_NAME sabat-viewer)

target_compile_features(sabat_viewer_exe PRIVATE cxx_std_23)

target_link_libraries(sabat_viewer_exe
    PRIVATE
        CLI11::CLI11
        ROOT::Eve
        ROOT::Gui
)

and CXX_FLAGS for sanitizer:

-DCMAKE_CXX_FLAGS="-U_FORTIFY_SOURCE -O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common"

Perhaps other sanitizer should be also tested.

Setup

ROOT v6.37.01
Built for linuxx8664gcc on Oct 20 2025, 11:23:48
From heads/cleanup@v6-37-01-7373-gf71ec8b9253
With c++ (Gentoo 15.2.0 p5) 15.2.0
Binary directory: /home/rafal/projects/cern/install/root_23/bin

Additional context

Hi, thanks for reaching out! We’ll investigate and let you know

1 Like

OK, two things, first, to fix your issue with pointers, create the event_viewer on the heap instead of on the stack, using the operator new:

    event_viewer *evi = new event_viewer(file, ascii_params, sabat_geometry);

At least that solved the issue for me:

Processing event_display2.C...
root [0]
Processing event_display2.C...
Info in <TGeoManager::TGeoManager>: Geometry Assemblies, Geometry using assemblies created
{void __cdecl event_viewer::ObstaclePropHandler::AlphaChanged(Int_t)}
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {0}
{void __cdecl event_viewer::ObstaclePropHandler::AlphaChanged(Int_t)}
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {0}
{void __cdecl event_viewer::ObstaclePropHandler::ScaleChanged(Int_t)}
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {0}
root [1] [{void __cdecl event_viewer::Next(void)}]  At event: {0} of {999} total.
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {1}
[{void __cdecl event_viewer::Next(void)}]  At event: {1} of {999} total.
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {2}
[{void __cdecl event_viewer::Next(void)}]  At event: {2} of {999} total.
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {3}
[{void __cdecl event_viewer::Prev(void)}]  At event: {3} of {999} total.
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {2}
[{void __cdecl event_viewer::Prev(void)}]  At event: {2} of {999} total.
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {1}
[{void __cdecl event_viewer::Prev(void)}]  At event: {1} of {999} total.
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {0}
[{void __cdecl event_viewer::Next(void)}]  At event: {0} of {999} total.
[{void __cdecl event_viewer::load_event(void)}]  this: {000001A66DFB5D30}   l_evt: {000001A674013350} l_all: {000001A674014CD0}  event: {1}

And then, a detail of layout/parent assignment with the TGLabels. Instead of:

            l_evt = new TGLabel(nullptr, "        ");
            group_event_current->AddFrame(l_evt, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 5, 0));
[...]
            l_all = new TGLabel(nullptr, "        ");
            group_event_all->AddFrame(l_all, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 5, 0));

You should do:

            l_evt = new TGLabel(group_event_current, "        ");
            group_event_current->AddFrame(l_evt, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 5, 0));
[...]
            l_all = new TGLabel(group_event_all, "        ");
            group_event_all->AddFrame(l_all, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 5, 0));

1 Like

Aaa, stupid mistake. I moved the logic from event_display function to main and forgot about stack object and its EOL. Thanks!

1 Like

You’re very welcome!