TCanvas->Update() hangs up code execution

In a while loop in a thread the function : load_datamodule(…) below is called and
this while loop is an infinite while(1) loop from which the break
occurs when the stop button is pressed or time is over.
The code hangs after the message :
I am here 010
i.e. it hangs in the code c124->Update(); #-o #-o #-o
The code works perfectly ok if the mouse cursor is moved across the screen. :smiley:
But if left idle for long the code hangs up here. #-o Kindly help me.

parts of code is as below :

HistWin::HistWin(const TGWindow *p,UInt_t w,UInt_t h) 
: TGMainFrame(p,w=1000,h=800)
{
p1 = p;
cout << "I am in HistWin constructor" << "\n" ;
cout << "before histwin1 = " << histwin1 << "\n" ;
histwin1++;
cout << "after histwin1 = " << histwin1 << "\n" ;

fHpx_waveMCA = NULL;
tracehist = NULL;

   // main frame
   fMainFrame2926 = new TGMainFrame(this,10,10,kMainFrame | kVerticalFrame);
   fMainFrame2926->SetName("fMainFrame2926");
   fMainFrame2926->SetLayoutBroken(kFALSE);

  // composite frame
   fMainFrame4041 = new TGCompositeFrame(fMainFrame2926,1024,705,kVerticalFrame);
   fMainFrame4041->SetName("fMainFrame4041");

   // vertical frame
   fVerticalFrame770 = new TGVerticalFrame(fMainFrame4041,1024,703,kVerticalFrame);
   fVerticalFrame770->SetName("fVerticalFrame770");
   fVerticalFrame770->SetLayoutBroken(kTRUE);

   // embedded canvas
   fRootEmbeddedCanvas799 = new TRootEmbeddedCanvas(0,fVerticalFrame770,1016,576);
   fRootEmbeddedCanvas799->SetName("fRootEmbeddedCanvas799");
   Int_t wfRootEmbeddedCanvas799 = fRootEmbeddedCanvas799->GetCanvasWindowId();
   c124 = new TCanvas("c124", 10, 10, wfRootEmbeddedCanvas799);
   fRootEmbeddedCanvas799->AdoptCanvas(c124);
   fVerticalFrame770->AddFrame(fRootEmbeddedCanvas799, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
   fRootEmbeddedCanvas799->MoveResize(2,2,1016,576);
......

int HistWin::load_datamodule(unsigned short mod3333, unsigned short chan3333)
{
	int retval;
	unsigned int NumWords ;
	NumWords = 32768;
	char hname1[10] =  "MCA" ;

	sprintf(nam101,"%04d_mod%02d.mca",run_no,mod3333);  // 0 for module no 0
	strcpy(filnamused,filnam);	
	strcat(filnamused , nam101);
	printf("In load_datamodule(..) ...Reading from Hist mode data file : %s\n",filnamused);

fNumberEntry976->SetIntNumber(channelNr);
fNumberEntry1254->SetIntNumber(moduleNr);
fTextEntry957->SetText(filnam);
fNumberEntry979->SetIntNumber(run_no);  // update "Run number"
fTextEntry1814->SetText(filnamused); 

	if (tracehist == NULL)
		tracehist = new unsigned int[NumWords];

	memset(tracehist, 0, NumWords * sizeof(unsigned int));


	printf("Reading Histogram from module: module no:%i , chan no.:%i \n",mod3333, chan3333);

retval = Pixie16ReadHistogramFromModule (tracehist, NumWords, mod3333, chan3333);
if(retval < 0)
{
// error handling
	if (retval == -1)
		{ std::cout << "retval = " << retval << " moduleNr = " << mod3333 << "\n";
		  std::cout << "Invalid Pixie-16 module number" << "\n";
		  std::cout << "Correct ModNum\n" << "\n";
		}
	else if (retval == -2)
		{ std::cout << "retval = " << retval << " ChanNum = " << chan3333 << "\n";
		  std::cout << "Invalid Pixie-16 channel number" << "\n";
		  std::cout << "Correct Channel Number" << "\n" ;
		}
	else if (retval == -3)
		{ std::cout << "retval = " << retval << "\n";
		  std::cout << "Failed to get the histogram data" << "\n";
		  std::cout << "Reboot the module" << "\n" ;
		}
	else {  std::cout << "Undocumented error" << "\n";     }
	return retval;
}
cout << "Success - Pixie16ReadHistogramFromModule (...)" << "\n";
char title01[20] = "data from module" ;
cout << "I am here 001" << "\n";
sprintf(histtitle,"%s,mod=%d,chan=%d", title01 ,mod3333, chan3333);
cout << "I am here 002" << "\n";
	if (fHpx_waveMCA == NULL ) {
		 	fHpx_waveMCA = new TH1I ( hname1 , histtitle , NumWords, 0, NumWords );  
			gStyle->SetOptStat(0);
			x_waveMCA = fHpx_waveMCA->GetXaxis();
				    }
	else { 	
		fHpx_waveMCA->SetTitle(histtitle); 
		cout << "I am here 00222" << "\n";  
	     }
cout << "I am here 003" << "\n";
	fHpx_waveMCA->UseCurrentStyle();
cout << "I am here 004" << "\n";
	xmaxint_waveMCA = x_waveMCA->GetLast();
	xminint_waveMCA = x_waveMCA->GetFirst();
cout << "I am here 005" << "\n";

fHpx_waveMCA->Reset();
cout << "I am here 006" << "\n";
	for ( int j = 0; j < NumWords ; j++)
		{  fHpx_waveMCA->Fill(j, int(tracehist[j]) );
		}
cout << "I am here 007" << "\n";
	c124->cd();cout << "I am here 008" << "\n";
	fHpx_waveMCA->DrawCopy();cout << "I am here 009" << "\n";
	c124->Modified();cout << "I am here 010" << "\n";
	c124->Update();cout << "I am here 011" << "\n";
	gSystem->ProcessEvents();cout << "I am here 012" << "\n";
return 1;
}  // int HistWin::load_datamodule(unsigned short mod3333, unsigned short chan3333)

the code hangs when left idle and again if the mouse cursor is moved the code resumes the execution
from the point at which it hung up. :^o #-o
I am confused as to what is to be done to get the code working flawlessly. #-o

What you describe suggests that your code is waiting for mouse events.
Have you setup a such thing somewhere ?

No Sir, I do not have any code waiting for mouse events.
In the …ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
code all the user interface code is there.
I suspect the following : :bulb:
I have 4 tabbed windows inside the main window,
I am updating via a timer message : calling a function which updates the widgets i.e
numEntry fields in different tabbed windows which may or maynot be visible at
the moment it is updated. Can this cause problems ? like the code gets stuck up there …?
:bulb:
Or maybe I need to write code to simulate the mouse movement effects :
like writing a timer driven function to switch or focus on my app or different windows of my app… :^o
does anybody have code to do the above or some suggestions :bulb:
or
Maybe I require a higher level system debugging tools for Linux, but right now I do not have time
for that, I don’t know what to do … #-o

Hard to tell without a program reproducing the problem.

Some times it hangs after the line
c124->Update();cout << “I am here 011” << “\n”;
and before
gSystem->ProcessEvents();cout << “I am here 012” << “\n”;

My program opens 3 windows and sometimes while minimising and maximising one of the windows
all 3 windows get stuck up - without getting updated and even the terminal window where the messages
are logged gets stuck up. Then moving the mouse cursor over the windows also does not help and
the program resumes only when a mouse pointer is clicked inside the terminal window displaying
the messages. #-o

As we said before we need a small reproducer.