I’m not running multiple threads, but I might be doing something wrong when I try to delete the elements.
The flow of the program is:
- Create first window using myClass::AddFrame (inherited from TGMainFrame) with an array of TGLabel and TGComboBox and one TGButton (all created on heap here)
- When the button is clicked call myClass::RemoveAll (also inherited from TGMainFrame), and delete all elements created on heap.
- Create second window in the same way the first one was created, using different elements among them a TGTab holding a TGTab.
- When this window is dismissed do the same thing as before, i.e. call myClass::RemoveAll, and then delete all elements created on heap (except for the tabs that were created as this causes a double-free for some reason)
- The third window is created with tabs and buttons, this triggers the crash
I tried checking which Button might have caused the crash using gdb, but I can’t really make sense of the output (I thought the name would be helpful, but it seems to be nonsense):
(gdb) p this->GetName()
Cannot access memory at address 0x646172676a05
(gdb) p this
$2 = (TGButton * const) 0x937cf90
(gdb) p this->fName
$3 = {_vptr.TString = 0xab112a0, fRep = {{fLong = {fCap = 112361616, fSize = 0, fData = 0xaaea540 "@Z\261\n"}, fShort = {fSize = 144 '\220', fData = "\200\262\006\000\000\000\000@\245\256\n\000\000\000"}, fRaw = {fWords = {112361616, 0,
179217728, 0}}}}, static kNPOS = -1, static fgIsA = {_M_b = {_M_p = 0x1890030}}}
(gdb) p this->fName.Data()
$4 = 0x937cfc9 "\200\262\006"
(gdb) p *this
$5 = {<TGFrame> = {<TGWindow> = {<TGObject> = {<TObject> = {_vptr.TObject = 0x64617267694d, fUniqueID = 0, fBits = 0, static fgDtorOnly = 0, static fgObjectStat = false, static fgIsA = {_M_b = {_M_p = 0x1737b40}}}, fId = 0,
fClient = 0x0, static fgIsA = {_M_b = {_M_p = 0x69dcad0}}}, fParent = 0x0, fNeedRedraw = 16, fName = {_vptr.TString = 0xab112a0, fRep = {{fLong = {fCap = 112361616, fSize = 0, fData = 0xaaea540 "@Z\261\n"}, fShort = {
fSize = 144 '\220', fData = "\200\262\006\000\000\000\000@\245\256\n\000\000\000"}, fRaw = {fWords = {112361616, 0, 179217728, 0}}}}, static kNPOS = -1, static fgIsA = {_M_b = {_M_p = 0x1890030}}}, static fgCounter = 6648,
fEditDisabled = 179416336, static fgIsA = {_M_b = {_M_p = 0x69dc110}}}, <TQObject> = {_vptr.TQObject = 0xab15a40, fListOfSignals = 0x937d010, fListOfConnections = 0xab16bb0, fSignalsBlocked = 96,
static fgAllSignalsBlocked = false, static fgIsA = {_M_b = {_M_p = 0x24e1ec0}}}, fX = 0, fY = 179312048, fWidth = 0, fHeight = 385, fMinWidth = 0, fMinHeight = 0, fMaxWidth = 0, fMaxHeight = 8384528, fBorderWidth = 0,
fOptions = 1, fBackground = 179129680, fEventMask = 179129704, fDNDState = 0, fFE = 0xaad4d68, static fgInit = true, static fgDefaultFrameBackground = 12632256, static fgDefaultSelectedBackground = 128,
static fgWhitePixel = 16777215, static fgBlackPixel = 0, static fgBlackGC = 0x24c1440, static fgWhiteGC = 0x24c11a0, static fgHilightGC = 0x29a9500, static fgShadowGC = 0x29f75b0, static fgBckgndGC = 0x29f7910,
static fgLastClick = 408662520, static fgLastButton = 1, static fgDbx = 549, static fgDby = 597, static fgDbw = 12588770, static fgUserColor = 0, static fgIsA = {_M_b = {_M_p = 0x3218000}}}, <TGWidget> = {
_vptr.TGWidget = 0x1300000013, fWidgetId = 1, fWidgetFlags = 0, fMsgWindow = 0xab15ba0, fCommand = {_vptr.TString = 0xab15bb8, fRep = {{fLong = {fCap = 179395512, fSize = 0, fData = 0xaaf6ab0 "0\a\257\n"}, fShort = {
fSize = 184 '\270', fData = "[\261\n\000\000\000\000\260j\257\n\000\000\000"}, fRaw = {fWords = {179395512, 0, 179268272, 0}}}}, static kNPOS = -1, static fgIsA = {_M_b = {_M_p = 0x1890030}}}, static fgIsA = {_M_b = {
_M_p = 0x6a2bb90}}}, fTWidth = 179268280, fTHeight = 0, fState = 179268280, fStayDown = false, fNormGC = 179395456, fUserData = 0x100000002, fTip = 0x0, fGroup = 0x40ce1042d3680bde, fBgndColor = 4741691291151532530,
fHighColor = 179415600, fStyle = 179415752, static fgDefaultGC = 0x29f6010, static fgHibckgndGC = 0x0, static fgReleaseBtn = 0, static fgIsA = {_M_b = {_M_p = 0x6afa620}}}
I also tried putting a cout statement in the TGButton::EmitSignals function to print the name of the button, but that simply causes the crash to happen when accessing the name:
#10 0x00007f235fc96b7e in tobuf (buf=<error reading variable>, x=10 '\n') at /opt/cern/root/root-6.24.02/core/base/inc/Bytes.h:63
It also gives some new error messages
input_line_99:2:2: error: source file is not valid UTF-8
<A0><F8>