Discussion:
[Foxgui-users] FXMenuCommand Question
slacknate
2016-06-14 13:07:31 UTC
Permalink
Hi all,

It has been a while since i have posted here, but I have a question about
the FOX widget tree destruction. My understanding is that when FXApp is
torn down/is deleted/goes out of scope it will also tear down all
accessible parts of the widget tree. Example:

#include <signal.h>
#include "fx/fx.h"
#include "mainwindow.h"


int main(int argc, char *argv[]) {

FXApp app("App Name", "Vendor Name");
app.init(argc, argv);

MainWindow *window = new MainWindow(&app);
app.addSignal(SIGINT, window, MainWindow::ID_QUIT);
app.create();
window->show(PLACEMENT_CURSOR);
window->setFocus();

return app.run(); // when run completes app goes out of scope and the
widget tree is destroyed
}

Now it seems, quite reasonably so, that FXMenuCommands would be part of
this process. However, when when I create an FXMenuCommand in main window
and do not explicitly delete it myself in the main window destructor, the
app segfaults in FXAccelTable::removeAccel. MainWindow constructor:

MainWindow::MainWindow(FXApp *app) :
FXMainWindow(app, "App Name", nullptr, nullptr, DECOR_ALL, 0, 0, 1024, 768)
{

FXMenuBar *menu_bar = new FXMenuBar(this, this,
FRAME_RAISED|LAYOUT_SIDE_TOP|LAYOUT_FILL_X);
FXMenuPane *menu = new FXMenuPane(this);

new FXMenuCommand(menu, "Menu Entry\tCtrl-M\tMenu Entry.", 0, this,
ID_DUT);
new FXMenuTitle(menu_bar, "&Menu", 0, menu);
}

So my question is: are FXMenuCommands supposed to be manually deleted or is
this an actual issue?
Nuri Boardman
2016-06-14 13:11:59 UTC
Permalink
from the FAQ http://www.fox-toolkit.org/


*Failing to delete menu panes in owner's destructor. *


When you create a MenuPane, the pointer passed in to MenuPane is the
*owner* of that MenuPane, which is typically a MainWindow or DialogBox.
This causes the MenuPane to stay on top of the owner window.

When adding a MenuCommand in a MenuPane, the MenuCommand will obtain the
owner of the MenuPane and install its accelerator in the owner's
accelerator table. This is necessary, as the accelerator is to be effective
without the MenuPane being having been popped up.

When the MenuCommand is destroyed, it tries to remove this accelerator
again by obtaining the MenuPane's owner and removing the accelerator from
the owner's accelerator table. Should it be the case that the owner of the
MenuPane had already been deleted, an access to a non-existing memory
location (segmentation fault) will likely occur.

Thus, it is necessary for the owner of a MenuPane to be still in
existence when the MenuPane itself is destroyed. So when the owner of a
MenuPane is destroyed, it must make sure the MenuPane is destroyed before
its destructor completes:- otherwise, the MenuPane would refer to a
non-existent owner.

As a general rule, shared resources such as Icons, Fonts, Cursors,
Bitmaps, and also MenuPanes, must be explicitly deleted by the widgets that
owns them.
Post by slacknate
Hi all,
It has been a while since i have posted here, but I have a question about
the FOX widget tree destruction. My understanding is that when FXApp is
torn down/is deleted/goes out of scope it will also tear down all
#include <signal.h>
#include "fx/fx.h"
#include "mainwindow.h"
int main(int argc, char *argv[]) {
FXApp app("App Name", "Vendor Name");
app.init(argc, argv);
MainWindow *window = new MainWindow(&app);
app.addSignal(SIGINT, window, MainWindow::ID_QUIT);
app.create();
window->show(PLACEMENT_CURSOR);
window->setFocus();
return app.run(); // when run completes app goes out of scope and the
widget tree is destroyed
}
Now it seems, quite reasonably so, that FXMenuCommands would be part of
this process. However, when when I create an FXMenuCommand in main window
and do not explicitly delete it myself in the main window destructor, the
FXMainWindow(app, "App Name", nullptr, nullptr, DECOR_ALL, 0, 0, 1024,
768) {
FXMenuBar *menu_bar = new FXMenuBar(this, this,
FRAME_RAISED|LAYOUT_SIDE_TOP|LAYOUT_FILL_X);
FXMenuPane *menu = new FXMenuPane(this);
new FXMenuCommand(menu, "Menu Entry\tCtrl-M\tMenu Entry.", 0, this,
ID_DUT);
new FXMenuTitle(menu_bar, "&Menu", 0, menu);
}
So my question is: are FXMenuCommands supposed to be manually deleted or
is this an actual issue?
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and
traffic
patterns at an interface-level. Reveals which users, apps, and protocols
are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Foxgui-users mailing list
https://lists.sourceforge.net/lists/listinfo/foxgui-users
slacknate
2016-06-14 13:15:28 UTC
Permalink
Oh wow. I've read the FAQ many times over the years and did not remember
seeing that... Thanks a bunch! :)
Glad the fix is a simple one!
Post by Nuri Boardman
from the FAQ http://www.fox-toolkit.org/
*Failing to delete menu panes in owner's destructor. *
When you create a MenuPane, the pointer passed in to MenuPane is the
*owner* of that MenuPane, which is typically a MainWindow or
DialogBox. This causes the MenuPane to stay on top of the owner window.
When adding a MenuCommand in a MenuPane, the MenuCommand will obtain
the owner of the MenuPane and install its accelerator in the owner's
accelerator table. This is necessary, as the accelerator is to be effective
without the MenuPane being having been popped up.
When the MenuCommand is destroyed, it tries to remove this accelerator
again by obtaining the MenuPane's owner and removing the accelerator from
the owner's accelerator table. Should it be the case that the owner of the
MenuPane had already been deleted, an access to a non-existing memory
location (segmentation fault) will likely occur.
Thus, it is necessary for the owner of a MenuPane to be still in
existence when the MenuPane itself is destroyed. So when the owner of a
MenuPane is destroyed, it must make sure the MenuPane is destroyed before
its destructor completes:- otherwise, the MenuPane would refer to a
non-existent owner.
As a general rule, shared resources such as Icons, Fonts, Cursors,
Bitmaps, and also MenuPanes, must be explicitly deleted by the widgets that
owns them.
Post by slacknate
Hi all,
It has been a while since i have posted here, but I have a question about
the FOX widget tree destruction. My understanding is that when FXApp is
torn down/is deleted/goes out of scope it will also tear down all
#include <signal.h>
#include "fx/fx.h"
#include "mainwindow.h"
int main(int argc, char *argv[]) {
FXApp app("App Name", "Vendor Name");
app.init(argc, argv);
MainWindow *window = new MainWindow(&app);
app.addSignal(SIGINT, window, MainWindow::ID_QUIT);
app.create();
window->show(PLACEMENT_CURSOR);
window->setFocus();
return app.run(); // when run completes app goes out of scope and
the widget tree is destroyed
}
Now it seems, quite reasonably so, that FXMenuCommands would be part of
this process. However, when when I create an FXMenuCommand in main window
and do not explicitly delete it myself in the main window destructor, the
FXMainWindow(app, "App Name", nullptr, nullptr, DECOR_ALL, 0, 0, 1024,
768) {
FXMenuBar *menu_bar = new FXMenuBar(this, this,
FRAME_RAISED|LAYOUT_SIDE_TOP|LAYOUT_FILL_X);
FXMenuPane *menu = new FXMenuPane(this);
new FXMenuCommand(menu, "Menu Entry\tCtrl-M\tMenu Entry.", 0, this,
ID_DUT);
new FXMenuTitle(menu_bar, "&Menu", 0, menu);
}
So my question is: are FXMenuCommands supposed to be manually deleted or
is this an actual issue?
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and
traffic
patterns at an interface-level. Reveals which users, apps, and protocols
are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports.
https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Foxgui-users mailing list
https://lists.sourceforge.net/lists/listinfo/foxgui-users
Jeroen
2016-06-14 13:20:36 UTC
Permalink
On Tue, 14 Jun 2016 09:07:31 -0400
Post by slacknate
Hi all,
It has been a while since i have posted here, but I have a question about
the FOX widget tree destruction. My understanding is that when FXApp is
torn down/is deleted/goes out of scope it will also tear down all
#include <signal.h>
#include "fx/fx.h"
#include "mainwindow.h"
int main(int argc, char *argv[]) {
FXApp app("App Name", "Vendor Name");
app.init(argc, argv);
MainWindow *window = new MainWindow(&app);
app.addSignal(SIGINT, window, MainWindow::ID_QUIT);
app.create();
window->show(PLACEMENT_CURSOR);
window->setFocus();
return app.run(); // when run completes app goes out of scope and the
widget tree is destroyed
}
Now it seems, quite reasonably so, that FXMenuCommands would be part of
this process. However, when when I create an FXMenuCommand in main window
and do not explicitly delete it myself in the main window destructor, the
FXMainWindow(app, "App Name", nullptr, nullptr, DECOR_ALL, 0, 0, 1024, 768)
{
FXMenuBar *menu_bar = new FXMenuBar(this, this,
FRAME_RAISED|LAYOUT_SIDE_TOP|LAYOUT_FILL_X);
FXMenuPane *menu = new FXMenuPane(this);
new FXMenuCommand(menu, "Menu Entry\tCtrl-M\tMenu Entry.", 0, this,
ID_DUT);
new FXMenuTitle(menu_bar, "&Menu", 0, menu);
}
So my question is: are FXMenuCommands supposed to be manually deleted or is
this an actual issue?
The FXMenuPane will delete its child-widgets when it is deleted. That
will thus take care of the FXMenuCommand.

However, the FXMenuPane is NOT a child widget of the FXMainWindow. It is
another kind of FXShell widget, i.e. direct child of FXRootWindow, and owned
by your MainWindow.

Thus, it must be deleted explicitly, by its owner, your MainWindow's destructor.


Hope this helps,

-- JVZ


--
+----------------------------------------------------------------------------+
| Copyright (C) 08:10 06/14/2016 Jeroen van der Zijp. All Rights Reserved. |
+----------------------------------------------------------------------------+
slacknate
2016-06-19 01:13:25 UTC
Permalink
Makes sense to me! Thanks again everyone!
Post by Jeroen
On Tue, 14 Jun 2016 09:07:31 -0400
Post by slacknate
Hi all,
It has been a while since i have posted here, but I have a question about
the FOX widget tree destruction. My understanding is that when FXApp is
torn down/is deleted/goes out of scope it will also tear down all
#include <signal.h>
#include "fx/fx.h"
#include "mainwindow.h"
int main(int argc, char *argv[]) {
FXApp app("App Name", "Vendor Name");
app.init(argc, argv);
MainWindow *window = new MainWindow(&app);
app.addSignal(SIGINT, window, MainWindow::ID_QUIT);
app.create();
window->show(PLACEMENT_CURSOR);
window->setFocus();
return app.run(); // when run completes app goes out of scope and the
widget tree is destroyed
}
Now it seems, quite reasonably so, that FXMenuCommands would be part of
this process. However, when when I create an FXMenuCommand in main window
and do not explicitly delete it myself in the main window destructor, the
FXMainWindow(app, "App Name", nullptr, nullptr, DECOR_ALL, 0, 0, 1024,
768)
Post by slacknate
{
FXMenuBar *menu_bar = new FXMenuBar(this, this,
FRAME_RAISED|LAYOUT_SIDE_TOP|LAYOUT_FILL_X);
FXMenuPane *menu = new FXMenuPane(this);
new FXMenuCommand(menu, "Menu Entry\tCtrl-M\tMenu Entry.", 0, this,
ID_DUT);
new FXMenuTitle(menu_bar, "&Menu", 0, menu);
}
So my question is: are FXMenuCommands supposed to be manually deleted or
is
Post by slacknate
this an actual issue?
The FXMenuPane will delete its child-widgets when it is deleted. That
will thus take care of the FXMenuCommand.
However, the FXMenuPane is NOT a child widget of the FXMainWindow. It is
another kind of FXShell widget, i.e. direct child of FXRootWindow, and owned
by your MainWindow.
Thus, it must be deleted explicitly, by its owner, your MainWindow's destructor.
Hope this helps,
-- JVZ
--
+----------------------------------------------------------------------------+
| Copyright (C) 08:10 06/14/2016 Jeroen van der Zijp. All Rights Reserved. |
+----------------------------------------------------------------------------+
Loading...