GUI crash with TGTextButton

Dear you,
My ROOT is ROOT 5.34/01 on SL6.3

I have a GUI interface with some TGTextButton, sometimes when I click a button, the program crashed and show something as following. Because the crash is not always happen, so it should be a crash during its running, I really don’t know what cause this crash. I just post these messages here, in hopes of someone will give me some advice. I am sorry that I can not prepare a minimal example reproducing this problem.

Any help or advice is appreciated,
Han

*** Break *** segmentation violation

There was a crash (#8 0x00fe81dd in SigHandler(ESignals) () from /opt/root//lib/libCore.so).
This is the entire stack trace of all threads:

Thread 12 (Thread 0xb6bffb70 (LWP 11568)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080721af in TDataReceiver::ReceiveData() ()
#4 0x080703e5 in TDataFileBuilder::ReceiveDataToFile(void*) ()
#5 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#6 0x00708a49 in start_thread () from /lib/libpthread.so.0
#7 0x01a17e1e in clone () from /lib/libc.so.6

Thread 11 (Thread 0xb61feb70 (LWP 11569)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080684e0 in TControl::recv_UDPBroadMessages(void*) ()
#4 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#5 0x00708a49 in start_thread () from /lib/libpthread.so.0
#6 0x01a17e1e in clone () from /lib/libc.so.6

Thread 10 (Thread 0xb55ffb70 (LWP 11578)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080721af in TDataReceiver::ReceiveData() ()
#4 0x080703e5 in TDataFileBuilder::ReceiveDataToFile(void*) ()
#5 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#6 0x00708a49 in start_thread () from /lib/libpthread.so.0
#7 0x01a17e1e in clone () from /lib/libc.so.6

Thread 9 (Thread 0xb49ffb70 (LWP 11579)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080684e0 in TControl::recv_UDPBroadMessages(void*) ()
#4 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#5 0x00708a49 in start_thread () from /lib/libpthread.so.0
#6 0x01a17e1e in clone () from /lib/libc.so.6

Thread 8 (Thread 0xb31ffb70 (LWP 11599)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080721af in TDataReceiver::ReceiveData() ()
#4 0x080703e5 in TDataFileBuilder::ReceiveDataToFile(void*) ()
#5 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#6 0x00708a49 in start_thread () from /lib/libpthread.so.0
#7 0x01a17e1e in clone () from /lib/libc.so.6

Thread 7 (Thread 0xb27feb70 (LWP 11600)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080684e0 in TControl::recv_UDPBroadMessages(void*) ()
#4 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#5 0x00708a49 in start_thread () from /lib/libpthread.so.0
#6 0x01a17e1e in clone () from /lib/libc.so.6

Thread 6 (Thread 0xb0fffb70 (LWP 11919)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080721af in TDataReceiver::ReceiveData() ()
#4 0x080703e5 in TDataFileBuilder::ReceiveDataToFile(void*) ()
#5 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#6 0x00708a49 in start_thread () from /lib/libpthread.so.0
#7 0x01a17e1e in clone () from /lib/libc.so.6

Thread 5 (Thread 0xb05feb70 (LWP 11920)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080684e0 in TControl::recv_UDPBroadMessages(void*) ()
#4 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#5 0x00708a49 in start_thread () from /lib/libpthread.so.0
#6 0x01a17e1e in clone () from /lib/libc.so.6

Thread 4 (Thread 0xae3feb70 (LWP 11975)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080684e0 in TControl::recv_UDPBroadMessages(void*) ()
#4 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#5 0x00708a49 in start_thread () from /lib/libpthread.so.0
#6 0x01a17e1e in clone () from /lib/libc.so.6

Thread 3 (Thread 0xacbffb70 (LWP 12011)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080721af in TDataReceiver::ReceiveData() ()
#4 0x080703e5 in TDataFileBuilder::ReceiveDataToFile(void*) ()
#5 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#6 0x00708a49 in start_thread () from /lib/libpthread.so.0
#7 0x01a17e1e in clone () from /lib/libc.so.6

Thread 2 (Thread 0xac1feb70 (LWP 12012)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x0070f818 in recvfrom () from /lib/libpthread.so.0
#2 0x0807ead5 in TUDPServerSocket::RecvRaw(char*, int) ()
#3 0x080684e0 in TControl::recv_UDPBroadMessages(void*) ()
#4 0x03e920fe in TThread::Function(void*) () from /opt/root//lib/libThread.so
#5 0x00708a49 in start_thread () from /lib/libpthread.so.0
#6 0x01a17e1e in clone () from /lib/libc.so.6

Thread 1 (Thread 0xb7804740 (LWP 11520)):
#0 0x0071e424 in __kernel_vsyscall ()
#1 0x019d66fb in waitpid () from /lib/libc.so.6
#2 0x019722a3 in do_system () from /lib/libc.so.6
#3 0x01972632 in system () from /lib/libc.so.6
#4 0x007107ed in system () from /lib/libpthread.so.0
#5 0x00fe2c6d in TUnixSystem::Exec(char const*) () from /opt/root//lib/libCore.so
#6 0x00fe943d in TUnixSystem::StackTrace() () from /opt/root//lib/libCore.so
#7 0x00fe80cf in TUnixSystem::DispatchSignals(ESignals) () from /opt/root//lib/libCore.so
#8 0x00fe81dd in SigHandler(ESignals) () from /opt/root//lib/libCore.so
#9 0x00fdf352 in sighandler(int) () from /opt/root//lib/libCore.so
#10
#11 0x0092a520 in TGText::SetCurrentRow(long) () from /opt/root//lib/libGui.so
#12 0x0092a5b9 in TGText::GetLineLength(long) () from /opt/root//lib/libGui.so
#13 0x009464ac in TGTextView::ToObjXCoord(long, long) () from /opt/root//lib/libGui.so
#14 0x00946b12 in TGTextView::DrawRegion(int, int, unsigned int, unsigned int) () from /opt/root//lib/libGui.so
#15 0x00951989 in TGView::ScrollCanvas(int, int) () from /opt/root//lib/libGui.so
#16 0x00950e0b in TGView::SetVisibleStart(int, int) () from /opt/root//lib/libGui.so
#17 0x0095109c in TGView::ProcessMessage(long, long, long) () from /opt/root//lib/libGui.so
#18 0x0089d908 in TGFrame::HandleClientMessage(Event_t*) () from /opt/root//lib/libGui.so
#19 0x0089dd4f in TGFrame::HandleEvent(Event_t*) () from /opt/root//lib/libGui.so
#20 0x00867ddb in TGClient::HandleEvent(Event_t*) () from /opt/root//lib/libGui.so
#21 0x00868c04 in TGClient::ProcessOneEvent() () from /opt/root//lib/libGui.so
#22 0x00868c6d in TGClient::HandleInput() () from /opt/root//lib/libGui.so
#23 0x00868ca0 in TGInputHandler::Notify() () from /opt/root//lib/libGui.so
#24 0x00fe680d in TUnixSystem::DispatchOneEvent(bool) () from /opt/root//lib/libCore.so
#25 0x00f61b44 in TSystem::InnerLoop() () from /opt/root//lib/libCore.so
#26 0x00f64099 in TSystem::Run() () from /opt/root//lib/libCore.so
#27 0x00f01717 in TApplication::Run(bool) () from /opt/root//lib/libCore.so
#28 0x0805f625 in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#11 0x0092a520 in TGText::SetCurrentRow(long) () from /opt/root//lib/libGui.so
#12 0x0092a5b9 in TGText::GetLineLength(long) () from /opt/root//lib/libGui.so
#13 0x009464ac in TGTextView::ToObjXCoord(long, long) () from /opt/root//lib/libGui.so
#14 0x00946b12 in TGTextView::DrawRegion(int, int, unsigned int, unsigned int) () from /opt/root//lib/libGui.so
#15 0x00951989 in TGView::ScrollCanvas(int, int) () from /opt/root//lib/libGui.so
#16 0x00950e0b in TGView::SetVisibleStart(int, int) () from /opt/root//lib/libGui.so
#17 0x0095109c in TGView::ProcessMessage(long, long, long) () from /opt/root//lib/libGui.so
#18 0x0089d908 in TGFrame::HandleClientMessage(Event_t*) () from /opt/root//lib/libGui.so
#19 0x0089dd4f in TGFrame::HandleEvent(Event_t*) () from /opt/root//lib/libGui.so
#20 0x00867ddb in TGClient::HandleEvent(Event_t*) () from /opt/root//lib/libGui.so
#21 0x00868c04 in TGClient::ProcessOneEvent() () from /opt/root//lib/libGui.so
#22 0x00868c6d in TGClient::HandleInput() () from /opt/root//lib/libGui.so
#23 0x00868ca0 in TGInputHandler::Notify() () from /opt/root//lib/libGui.so
#24 0x00fe680d in TUnixSystem::DispatchOneEvent(bool) () from /opt/root//lib/libCore.so
#25 0x00f61b44 in TSystem::InnerLoop() () from /opt/root//lib/libCore.so
#26 0x00f64099 in TSystem::Run() () from /opt/root//lib/libCore.so
#27 0x00f01717 in TApplication::Run(bool) () from /opt/root//lib/libCore.so
#28 0x0805f625 in main ()

Hi,

It is difficult to help without seeing a single line of code… It could be a problem of race condition with a thread trying to update the text view. A minimal running example reproducing the problem would definitively help…

Cheers, Bertrand.

Dear Bertrand,
Thank you very much.

I also think that this error may has some relation with TGTextView, however I can not get the point which cause this problem. The GUI interface section of my program is similar to the example in one of my previous post [url]GUI crash with TGTextButton In that example there is a TGTextView, which is actived to show some text by a signal/slot. Sometimes when a TGTextButton emit a signal (or more than one signal) to active the TGTextView to show some text (more than one thread will visit the some TGTextView simultaneously, I think this may happen in my program), the GUI section will crash and show these error messages.
And what do you mean of “[color=#FF0000]race condition[/color]”? I am not good at C++, does this means that more than one thread go to use something (for example a TGTextView) simultaneously? Should I use TThread::Lock()/TThread::Unlock() functions?

Would you please give me some more advice to help me find out what really cause this problem.

Best wishes,
Han

Dear Han,

[quote=“handong”]And what do you mean of “race condition”? I am not good at C++, does this means that more than one thread go to use something (for example a TGTextView) simultaneously?[/quote]Yes, for example the main thread trying to update something being modified by another thread…

[quote=“handong”]does this means that more than one thread go to use something (for example a TGTextView) simultaneously[/quote]Maybe… You are the only one knowing what your code is doing… :wink:

[quote=“handong”]Should I use TThread::Lock()/TThread::Unlock() functions?[/quote]Well, it could help, depending what is the problem… You should definitively try to catch the crash in a debugger, and see where it comes from.
BTW, do you really need threads?

Cheers, Bertrand.

Dear Bertrand,

Yes, I need TThread. My program will run on more than 1 computer, and some threads are used for communiction between these computers with TSocket. The program includes more than 3000 lines, if I upload it here, it maybe a waste of your time.

I will try to do that, however I know only a little about gdb.

The GUI interface section of my program is similar to the example [url]GUI crash with TGTextButton I have done a little modification, and I upload it here again.

OK, now let my try to make my question clearly, I do not want to waste your time.

  1. I modified the example program by using TTimer, just as your suggestion in [url]GUI crash with TGTextButton it works OK under Windows7.

  2. I think it maybe the “TGTextView->Update()” funciton cause the crash of my program, so I change the “TGTextView->AddLineFast(text)” to “TGTextView->AddLine(text)”, in this way it not need to call “TGTextView->Update()”. But there is a new problem, the function “void TTestFrame::ClearTextView()” (refer to the example in ‘TTestFrame.cpp’, the function should delete the oldest line if total number of lines > 5) do not work correctly. [color=#FF0000]You can run the example under Linux[/color], and you will noticed that, the lines in the TGTextView do not ‘go up’, only the latest line changed(even if I change TGText->DelLine(1) to TGText->DelLine(5)). What should I do to make “void TTestFrame::ClearTextView()” work correctely.

I check my program step by step, trying to find out what makes it crash, so I want to solve the problem first.

Best wishes,
Han
guicrash.rar (19.2 KB)

Dear Bertrand,

I use GDB to debug my program and caught some messages as following. I found that my program crash on the function “TGText::SetCurrentRow(long)” very often. In the error message, some lines(in red) show the function of my program, I will post these functions here.
Would you please kindly give me some help.
Han

Program received signal SIGSEGV, Segmentation fault.
[color=#FF0000]0x00657560 in TGText::SetCurrentRow(long) () from /opt/root//lib/libGui.so[/color]
(gdb) bt
#0 0x00657560 in TGText::SetCurrentRow(long) () from /opt/root//lib/libGui.so
#1 0x006575b9 in TGText::GetLineLength(long) () from /opt/root//lib/libGui.so
#2 0x00672ba0 in TGTextView::ReturnLongestLineWidth() () from /opt/root//lib/libGui.so
#3 0x00671d51 in TGTextView::HLayout() () from /opt/root//lib/libGui.so
#4 0x00671ca0 in TGTextView::Layout() () from /opt/root//lib/libGui.so
#5 0x00671385 in TGTextView::Update() () from /opt/root//lib/libGui.so
[color=#FF0000]#6 0x0806b39b in TControlFrame::ShowEventNum (this=0xbffff05c, num=2545) at TControlFrame.cpp:296[/color]
[color=#FF0000]#7 0x080735b7 in TMasterTask::ShowEventNumByTimer (this=0xbffff05c) at TMasterTask.cpp:132[/color]
#8 0x08091ea3 in G__classDict_631_0_32 (result7=0x8679a64, funcname=0x0, libp=0x8679ac0, hash=0)
at classDict.cpp:3399
#9 0x013169b8 in Cint::G__CallFunc::Execute(void*) () from /opt/root//lib/libCint.so
#10 0x00cd2cbb in TCint::CallFunc_Exec(void*, void*) const () from /opt/root//lib/libCore.so
#11 0x00c6b63a in TQConnection::ExecuteMethod() () from /opt/root//lib/libCore.so
#12 0x00c704d5 in TQObject::Emit(char const*) () from /opt/root//lib/libCore.so
#13 0x005938ea in TTimer::Timeout() () from /opt/root//lib/libGui.so
#14 0x00ca15f1 in TTimer::Notify() () from /opt/root//lib/libCore.so
#15 0x00ca1257 in TTimer::CheckTimer(TTime const&) () from /opt/root//lib/libCore.so
#16 0x00d0f0aa in TUnixSystem::DispatchTimers(bool) () from /opt/root//lib/libCore.so
#17 0x00d1397c in TUnixSystem::DispatchOneEvent(bool) () from /opt/root//lib/libCore.so
#18 0x00c8eb44 in TSystem::InnerLoop() () from /opt/root//lib/libCore.so
#19 0x00c91099 in TSystem::Run() () from /opt/root//lib/libCore.so
#20 0x00c2e717 in TApplication::Run(bool) () from /opt/root//lib/libCore.so
[color=#FF0000]#21 0x0805f975 in main (argc=1, argv=0xbffff354) at ControlPC.cpp:29[/color]

[color=#FF0000]TControlFrame::ShowEventNum (this=0xbffff05c, num=2545) at TControlFrame.cpp:296[/color]
The line “[color=#FF0000]fvieweventnum->Update();[/color]” is the line numbered ‘[color=#FF0000]296[/color]’, “fvieweventnum” is a “TGTextView”.

void TControlFrame::ShowEventNum(int num)
{
	TString chnum = TString::Format("%09d", num);
	TThread::Lock(); 
	ClearEventNum();
	fvieweventnum->AddLineFast(chnum.Data());
	fvieweventnum->Update(); //This line is refered by the error message
	//fvieweventnum->AddLine(chnum.Data());
	fvieweventnum->ShowBottom();
	TThread::UnLock(); 
}

“ClearEventNum();” function in the upper code is as following.

void TControlFrame::ClearEventNum()
{
	TThread::Lock(); 
	if(fvieweventnum->ReturnLineCount()>=50)
	{
		fvieweventnum->GetText()->DelLine(1);
	}
	TThread::UnLock(); 
}

[color=#FF0000]0x080735b7 in TMasterTask::ShowEventNumByTimer (this=0xbffff05c) at TMasterTask.cpp:132[/color].
The line “ShowEventNum(evtnum);” is the line numbered ‘[color=#FF0000]132[/color]’.

void TMasterTask::ShowEventNumByTimer()
{
	static int oldevtnum = 0; 
	int evtnum = TDataFileBuilder::eventcounter;
	if(evtnum != oldevtnum)
	{
		oldevtnum = evtnum;
		TThread::Lock();
		ShowEventNum(evtnum);
		TThread::UnLock();
	}
}

[color=#FF0000]0x0805f975 in main (argc=1, argv=0xbffff354) at ControlPC.cpp:29[/color]
This is the main function. The line “apponline.Run();” is the line numbered ‘[color=#FF0000]29[/color]’.

int main(int argc, char *argv[])
{
	TApplication apponline("Online", &argc, argv);

	TControl masterpc("192.168.47.128", CONTROL_PC); //192.0.0.17

	TMasterTask mastask(masterpc);

	apponline.Run();
	return 0;
}

Dear Han,

Well, I’m not sure you really need threads for that. Did you try $ROOTSYS/tutorials/net/hserv.C and $ROOTSYS/tutorials/net/hclient.C tutorials? Those are socket examples not using any thread…

Anyway, it looks like it is crashing at the same place than in your other post, and I don’t see how else to fix this. But I’ll try your code and see if I can find a solution…

Cheers, Bertrand.

Dear Bertrand,
Thank you very much for your help.

a. I have [color=#FF0000]only two threads in my program[/color]. In the begaining of this post you see a lot threads, that is because one of the two thread is not closed correctly(a Socket receive funtion blocks this thread), now this problem have been fixed.
b. I used a lot of TThread::Lock()/UnLock() functions, [color=#FF0000]however that is not really for threads[/color]. I use TThread::Lock()/UnLock() to avoid that a “signal” trigger two “slot” functions, in which the “ShowText()” function is called. Something like the following (just used to explain my privous presentation, not real functions):

mascontrol.Connect("MSignalEmit()",  Class_Name(), this, "ShowMessageSignal()");
mascontrol.Connect("MSignalEmit()",  Class_Name(), this, "BroadMessageSignal()");

void ShowMessageSignal() //Signal
{
	TThread::Lock(); //lock the main mutex
	ShowText("Set File Heaer OK.");
	TThread::UnLock(); //unlock the main mutex
}

void BroadMessageSignal() //Signal
{
	TThread::Lock(); //lock the main mutex
	ShowText("Set File Heaer OK.");
	TThread::UnLock(); //unlock the main mutex
}

as showed in this example, the signal “MSignalEmit()” will trigger the two slot functions and the two slot functions will call “ShowText()” simultaneously, the TThread::Lock()/UnLock() function just used to avoid the simultaneously call of the “ShowText()” function,[color=#FF0000]however I do not know this will work just as what am I designed or not[/color].

c. I have tried the example $ROOTSYS/tutorials/net/hserv.C and $ROOTSYS/tutorials/net/hclient.C, the “TSocekt” part of my program is base on this example.

I change the the “ShowText()” function to the following:

void TControlFrame::ShowText(const char *text)
{
	TThread::Lock(); //lock the main mutex
	//ClearTextView();
	//fviewText->AddLineFast(text);
	//fviewText->Update();
	fviewText->AddLine(text);
	fviewText->ShowBottom();
	TThread::UnLock(); //unlock the main mutex
}

i.e. eliminate the “ClearTextView();” “fviewText->Update();” and change “fviewText->AddLineFast(text);” to “fviewText->AddLine(text);”, the GDB given the same error messages.

PS. I will try to predigest my program to make a minimal example reproducing this problem.

Best wishes,
Han