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++ TheIDE » U++ TheIDE: Other Features Wishlist and/or Bugs » BUG: "Close();" does not!
BUG: "Close();" does not! [message #41877] Mon, 03 February 2014 07:38 Go to next message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
Using svn 6840 on debian:

The call to Close() in following does not close the window:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class testclose : public TopWindow
{
public:
	typedef testclose CLASSNAME;
	testclose();
	
	ArrayCtrl ar;
	
	void armenu(Bar &bar);
	void DoClose();
};

testclose::testclose()
{
	Title("testclose");
	SetRect(100,100,300,300);
	
	ar.SetRect(2,2,200,200);
	Add(ar);
	
	ar.WhenBar = THISBACK(armenu);
}

GUI_APP_MAIN
{
	testclose().Run();
}

void testclose::armenu(Bar &bar)
{
	bar.Add("Close", THISBACK(DoClose));
}

void testclose::DoClose()
{
	Close();
}


If I call DoClose() from a button.WhenPush(..) it works; from a window menu, it works, but from this popup-menu it does not .. ?


[Updated on: Mon, 03 February 2014 12:16]

Report message to a moderator

Re: "Close();" does not! [message #41878 is a reply to message #41877] Mon, 03 February 2014 10:33 Go to previous messageGo to next message
Shire is currently offline  Shire
Messages: 41
Registered: September 2006
Location: Russia, Yamal peninsula
Member
Offtopic. This post is for CtrlLib package.

You call Close() of top window from inner event loop (context menu loop). Top window cannot safely terminate inner event loop.

But you can use this workaround:
PostCallback(THISBACK(Close));


Indeed, this situation must be asserted in library, silent return is never good.
Re: "Close();" does not! [message #41880 is a reply to message #41878] Mon, 03 February 2014 12:09 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
Quote:

But you can use this workaround:

Quote:

PostCallback(THISBACK(Close));




I replaced 'Close();' with above call, but it has no effect.

My opinion: the call to Close() should work from anywhere and
any 'housekeeping' to make that work should not be my concern?
Re: "Close();" does not! [message #41881 is a reply to message #41880] Mon, 03 February 2014 14:22 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1096
Registered: August 2007
Senior Contributor
As Shire already mentioned, and as far as I know, you cannot directly call the TopWindow::Close() from an inner event loop (but it seems relatively safe, since if called from an inner loop, Close() method does nothing and simply returns). I might be wrong, but afaik, buttons, top menu etc. does not have a seperate event loop, they pass their events to their parent (here, TopWindow). On the other hand, popup menu and modal dialogues have an inner loop (you can see they are invoked by methods such as Do(), Run(), Execute())

For example, you could have called Close() if the menu was a direct children of topwindow (a top menu). In this case, you are calling from inside an popup menu of ArrayCtrl (which probably invokes the MenuBar::Execute() method) , so you need to break the top level event loop "explicitly". Use TopWindow::Break().


void testclose::DoClose()
{
 // Breaks the TopWindow event loop.
 Break();
}





Also, note that TopWindow::Close() method is virtual, you can override it to suit your needs.

Regards.


[Updated on: Mon, 03 February 2014 14:52]

Report message to a moderator

Re: BUG: "Close();" does not! [message #41882 is a reply to message #41877] Mon, 03 February 2014 15:43 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
Possible solution:

void testclose::DoClose()
{
	static int cb=0;
	if (!cb) { cb=1; SetTimeCallback(10, THISBACK(DoClose), 0); }
	else Close();
}


The PostCallBack(..)-function does the above but with a 1 ms delay
and my version just increases that time-out value.
This seems a cleaner way than calling Break() ( - the word 'break'
sounds like things won't end nicely Smile
Re: BUG: "Close();" does not! [message #41899 is a reply to message #41882] Wed, 05 February 2014 03:13 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I had considerable problems closing threads from the main.

Having each thread close itself from INSIDE that thread was the only positive and error free method that I found.
Re: BUG: "Close();" does not! [message #41902 is a reply to message #41899] Wed, 05 February 2014 08:50 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
Quote:


Having each thread close itself from INSIDE that thread was the only positive and error free method that I found.



Considering the above - would the possible solution I suggest be safe?
Re: BUG: "Close();" does not! [message #41910 is a reply to message #41899] Wed, 05 February 2014 13:45 Go to previous message
Shire is currently offline  Shire
Messages: 41
Registered: September 2006
Location: Russia, Yamal peninsula
Member
Quote:


Having each thread close itself from INSIDE that thread was the only positive and error free method that I found.



This is true, normally, thread must do proper uninitialization by itself. Any outside intervention knows nothing about thread stack objects (and allocated resources) and terminating thread is chance of memory leak.

You can tell thread about exiting via bool flag. There is global flag, managed by Thread::ShutdownThreads, or you can create thread own flag.
Previous Topic: Unability to debug
Next Topic: Problematic hack in upp::Build.cpp
Goto Forum:
  


Current Time: Sun Jun 23 11:03:53 CEST 2024

Total time taken to generate the page: 0.01203 seconds