Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Random problems with destructors in GUI classes
icon4.gif  Random problems with destructors in GUI classes [message #49421] Thu, 08 February 2018 10:11 Go to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
Hello all

I have random problems with GUI controls. Sometimes with DEBUG or RELEASE, when a control is destructed an EXCEPTION_ACCESS_VIOLATION exception raises. This happens in ScatterCtrl.
For example, function ScatterCtrl::DoShowEditDlg() calls PropertiesDlg(*this, itab).Run(true) opening a dialog.
Sometimes, when this dialog is closed, this errror raises. The function call stack represets basically destructors:

index.php?t=getfile&id=5501&private=0

It is like there is a problem in the destructors order, so that in this case, when ColorPusher destructor is called, parent controls has been already destructed.

I have seen that many or maybe all GUI controls have virtual destructors. Maybe it has no sense but, should GUI user controls destructors have to be also virtual?


Best regards
Iñaki

[Updated on: Thu, 08 February 2018 10:14]

Report message to a moderator

Re: Random problems with destructors in GUI classes [message #49422 is a reply to message #49421] Thu, 08 February 2018 11:12 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1756
Registered: August 2008
Location: Czech Republic
Senior Contributor

Hi Koldo,

You are right about the virtual destructors. If you have virtual inheritance, you must always declare virtual destructor, even if it doesn't do anything. Have at the discussion here for some details why it is required.

Best regards,
Honza
Re: Random problems with destructors in GUI classes [message #49423 is a reply to message #49422] Thu, 08 February 2018 11:25 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
Thank you Honza

This would mean that all GUI user classes must have virtual destructors?


Best regards
Iñaki
Re: Random problems with destructors in GUI classes [message #49424 is a reply to message #49423] Thu, 08 February 2018 12:40 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1756
Registered: August 2008
Location: Czech Republic
Senior Contributor

koldo wrote on Thu, 08 February 2018 11:25
Thank you Honza

This would mean that all GUI user classes must have virtual destructors?

Yes, because they are probably always released via Ctrl* pointer. Non-virtual destructor is not called in such case.

Honza
Re: Random problems with destructors in GUI classes [message #49425 is a reply to message #49421] Thu, 08 February 2018 13:02 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
Oupss! Thank you again

I should have to review many classes to include this.

Probably I have not realised about that, but we would have to include this in the documentation.


Best regards
Iñaki
Re: Random problems with destructors in GUI classes [message #49432 is a reply to message #49423] Fri, 09 February 2018 13:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
koldo wrote on Thu, 08 February 2018 11:25
Thank you Honza

This would mean that all GUI user classes must have virtual destructors?


'virtuality' of destructor is inherited. Since Ctrl has virtual destructor, it is not really necessarry to declare destructor virtual in derived classes.
Re: Random problems with destructors in GUI classes [message #49433 is a reply to message #49421] Fri, 09 February 2018 13:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
koldo wrote on Thu, 08 February 2018 10:11
Hello all

I have random problems with GUI controls. Sometimes with DEBUG or RELEASE, when a control is destructed an EXCEPTION_ACCESS_VIOLATION exception raises. This happens in ScatterCtrl.
For example, function ScatterCtrl::DoShowEditDlg() calls PropertiesDlg(*this, itab).Run(true) opening a dialog.
Sometimes, when this dialog is closed, this errror raises. The function call stack represets basically destructors:

index.php?t=getfile&id=5501&private=0

It is like there is a problem in the destructors order, so that in this case, when ColorPusher destructor is called, parent controls has been already destructed.

I have seen that many or maybe all GUI controls have virtual destructors. Maybe it has no sense but, should GUI user controls destructors have to be also virtual?


With very little info you have provided I would actually think that the problem here is properties dialog is already deleted when the constructor is invoked - but that is just the first thing I would check.

I have tried to identify the problem in trunk, but all seems OK there. Is this trunk code or some new development?
Re: Random problems with destructors in GUI classes [message #49443 is a reply to message #49433] Sat, 10 February 2018 23:53 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
Hello Mirek

I did not know that 'virtuality' of destructor is inherited. In fact high level U++ GUI classes like ArrayCtrl have empty virtual destructors.

Now all code is uploaded.

Virtualizing all destructors has not solved the issue.

It is like some destructor supposes that parent control already has not been closed.

Two samples:
index.php?t=getfile&id=5502&private=0

index.php?t=getfile&id=5503&private=0


Best regards
Iñaki

[Updated on: Sun, 11 February 2018 00:10]

Report message to a moderator

Re: Random problems with destructors in GUI classes [message #49444 is a reply to message #49443] Sun, 11 February 2018 08:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
koldo wrote on Sat, 10 February 2018 23:53
Hello Mirek

I did not know that 'virtuality' of destructor is inherited. In fact high level U++ GUI classes like ArrayCtrl have empty virtual destructors.


That was workaround for some old compiler bug.

Quote:

It is like some destructor supposes that parent control already has not been closed.


Indeed. However, I am unable to reproduce so far.

Is this some sort of new behaviour? (Like: has this started to happen since some time? Have you changed anything in ScatterCtrl?)

Any tips how to reproduce?

Quote:

Two samples:
index.php?t=getfile&id=5502&private=0

index.php?t=getfile&id=5503&private=0

[/quote]

BTW, you can copy backtrace to clipboard using Debug/Copy backtrace
Re: Random problems with destructors in GUI classes [message #49445 is a reply to message #49444] Sun, 11 February 2018 08:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
void PropertiesDlg::OnClose() 
{
	measures.Change();
	
	RejectBreak(IDOK);
	Close();	Close();
}


It should not be a reason for these problems, but Break should be enough here. Why do you call Close twice after that?

Mirek
Re: Random problems with destructors in GUI classes [message #49446 is a reply to message #49445] Sun, 11 February 2018 09:27 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
mirek wrote on Sun, 11 February 2018 08:33
void PropertiesDlg::OnClose() 
{
	measures.Change();
	
	RejectBreak(IDOK);
	Close();	Close();
}


It should not be a reason for these problems, but Break should be enough here. Why do you call Close twice after that?

Mirek

It was necessary in the past. Now is not. I have just deleted it.


Best regards
Iñaki

[Updated on: Sun, 11 February 2018 23:05]

Report message to a moderator

Re: Random problems with destructors in GUI classes [message #49453 is a reply to message #49446] Mon, 12 February 2018 22:24 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
Well, this does not solve the problem but solves the exception:

void ScatterCtrl::DoShowData() 
{
	static DataDlg dlg;
	ONCELOCK {
		dlg.Init(*this);
	}
	dlg.Run(true);
}

It has been applied to all problematic dialogs. The problems have not been repeated.


Best regards
Iñaki
Re: Random problems with destructors in GUI classes [message #49454 is a reply to message #49453] Mon, 12 February 2018 23:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
koldo wrote on Mon, 12 February 2018 22:24
Well, this does not solve the problem but solves the exception:

void ScatterCtrl::DoShowData() 
{
	static DataDlg dlg;
	ONCELOCK {
		dlg.Init(*this);
	}
	dlg.Run(true);
}

It has been applied to all problematic dialogs. The problems have not been repeated.


OK, that would mean the cause probably really is some destruction order issue. Now we should find and fix it for real...

BTW, why do you use appmodal mode (Run(true))? That is not standard.
Re: Random problems with destructors in GUI classes [message #49455 is a reply to message #49454] Tue, 13 February 2018 10:53 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
Quote:
BTW, why do you use appmodal mode (Run(true))? That is not standard.


What do you recommend?


Best regards
Iñaki
Re: Random problems with destructors in GUI classes [message #49489 is a reply to message #49455] Sat, 17 February 2018 12:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
koldo wrote on Tue, 13 February 2018 10:53
Quote:
BTW, why do you use appmodal mode (Run(true))? That is not standard.


What do you recommend?


true blocks all application windows, which sometimes is not quite right. Just use Run(), which defaults to false and blocks only current main window.
Re: Random problems with destructors in GUI classes [message #49492 is a reply to message #49489] Sun, 18 February 2018 10:06 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
OK. Thank you.

Best regards
Iñaki
Re: Random problems with destructors in GUI classes [message #49526 is a reply to message #49453] Sat, 24 February 2018 10:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
koldo wrote on Mon, 12 February 2018 22:24
Well, this does not solve the problem but solves the exception:

void ScatterCtrl::DoShowData() 
{
	static DataDlg dlg;
	ONCELOCK {
		dlg.Init(*this);
	}
	dlg.Run(true);
}

It has been applied to all problematic dialogs. The problems have not been repeated.


This is fatal error.

a) it will crash if you close scatter ctrl and create another one (because dlg will keep pointer to nonexisting ScatterCtrl)
b) it will behave incorrectly with 2 ScatterCtrls
c) it must work without such trick
Re: Random problems with destructors in GUI classes [message #49527 is a reply to message #49526] Sat, 24 February 2018 12:40 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
I have done a light cleanup of ScatterCtrl code, removing unnecessarry things. Might have fixed the issue, but unlikely.

In any case, I really have problem to reproduce the issue. Need your help.
Re: Random problems with destructors in GUI classes [message #49564 is a reply to message #49527] Fri, 02 March 2018 15:00 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2921
Registered: August 2008
Veteran
Finally the cause was totally unrelated with ScatterCtrl and was caused by SetTimeCallbacks not handled properly.

It has been difficult to find this, but the problems must not be swept under the carpet, and the root cause of them has to be found. A patch is not a solution Smile


Best regards
Iñaki
Re: Random problems with destructors in GUI classes [message #49565 is a reply to message #49564] Fri, 02 March 2018 15:07 Go to previous message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
koldo wrote on Fri, 02 March 2018 15:00
Finally the cause was totally unrelated with ScatterCtrl and was caused by SetTimeCallbacks not handled properly.

It has been difficult to find this, but the problems must not be swept under the carpet, and the root cause of them has to be found. A patch is not a solution Smile


Excellent! Thank you for the hard work.

I know how complicated it is sometimes. I remember hunting RichEdit bug for two years - it was randomly crashing in my app, like once a month.... (it turned out to be invalid READ - most of time it harmlessly read some random data, but once a month it hit not yet reserved memory).
Previous Topic: FOUR State Option button
Next Topic: Ctrl creation via dll stuff
Goto Forum:
  


Current Time: Sun Feb 17 10:42:06 CET 2019

Total time taken to generate the page: 0.01053 seconds