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  |
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 #41881 is a reply to message #41880] |
Mon, 03 February 2014 14:22   |
Oblivion
Messages: 1202 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.
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 03 February 2014 14:52] Report message to a moderator
|
|
|
|
|
|
Re: BUG: "Close();" does not! [message #41910 is a reply to message #41899] |
Wed, 05 February 2014 13:45  |
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.
|
|
|
Goto Forum:
Current Time: Fri Apr 25 21:28:36 CEST 2025
Total time taken to generate the page: 0.00866 seconds
|