Is is possible to have a context menu in modal dialog?
If I try to have a context meu in modal dialog I get
unhandled exception, while modal dialog destructor is
executing.
I duplicated the problem, but have not solved it yet.
Here is what I know:
In class MessageMapPolicyModalDialogWidget of file MessageMapPolicyClasses.h
the kill function calls the function
killChildren(); // needed for resource based WidgetModalDialogs.
but one of the elements in the itsChildren vector of the WidgetModalDialog has HWND of
feeefeee and looks to be already destroyed. Anyhow it is no longer a valid object and so
crashes just before a delete when there is a RTTI check. If you comment out the killChildren
line then pure ModalDialogs will work, but those using resource based widgets will have
memory leaks.
I'll check in a test for this problem in WidgetModalDialog, just uncoment #define TRY_CONTEXT
t see the problem. Andrew
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Finally figured out the cause of the problem- The WidgetMenu code for appendPopup was adding the Popup menu to the grandparents instead of the parent's itsChildren list.
WidgetMenuPtr retVal = WidgetMenuPtr( new WidgetMenu< EventHandlerClass, MessageMapPolicy >( this ) );
Also WidgetMenu constructor was using the Widget constructor that put the first popup menu in the itsChildren list of the modal dialog.
This is the new WidgetMenu constructor:
template< class EventHandlerClass, class MessageMapPolicy >
WidgetMenu< EventHandlerClass, MessageMapPolicy >::WidgetMenu( SmartWin::Widget * parent )
: Widget( 0 )
, isSysMenu( false )
{
// We construct Widget(0) so that the WidgetMenu is not placed in parent->itsChildren
// (If a WidgetMenu is in parent->Children then WidgetModalDialog crashs during cleanup.
xAssert( parent, _T( "Can't have a Menu without a parent..." ) );
itsParent= parent; // But eventually we do want to know its parent.
}
Modal dialogs, being different, have different destruction code, and having menu objects in itsChildren list causes the non-rtti crash.
Anyhow a fix is coming, after more testing.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: NO
my email address: ppikulski@poczta.onet.pl
Logged In: YES
user_id=1157678
Thanks for the error report!
I duplicated the problem, but have not solved it yet.
Here is what I know:
In class MessageMapPolicyModalDialogWidget of file MessageMapPolicyClasses.h
the kill function calls the function
killChildren(); // needed for resource based WidgetModalDialogs.
but one of the elements in the itsChildren vector of the WidgetModalDialog has HWND of
feeefeee and looks to be already destroyed. Anyhow it is no longer a valid object and so
crashes just before a delete when there is a RTTI check. If you comment out the killChildren
line then pure ModalDialogs will work, but those using resource based widgets will have
memory leaks.
I'll check in a test for this problem in WidgetModalDialog, just uncoment #define TRY_CONTEXT
t see the problem. Andrew
Logged In: YES
user_id=1157678
Originator: NO
Finally figured out the cause of the problem- The WidgetMenu code for appendPopup was adding the Popup menu to the grandparents instead of the parent's itsChildren list.
//WidgetMenuPtr retVal = WidgetMenuPtr( new WidgetMenu< EventHandlerClass, MessageMapPolicy >( this->Widget::itsParent ) );
// Should be the below instead:
WidgetMenuPtr retVal = WidgetMenuPtr( new WidgetMenu< EventHandlerClass, MessageMapPolicy >( this ) );
Also WidgetMenu constructor was using the Widget constructor that put the first popup menu in the itsChildren list of the modal dialog.
This is the new WidgetMenu constructor:
template< class EventHandlerClass, class MessageMapPolicy >
WidgetMenu< EventHandlerClass, MessageMapPolicy >::WidgetMenu( SmartWin::Widget * parent )
: Widget( 0 )
, isSysMenu( false )
{
// We construct Widget(0) so that the WidgetMenu is not placed in parent->itsChildren
// (If a WidgetMenu is in parent->Children then WidgetModalDialog crashs during cleanup.
xAssert( parent, _T( "Can't have a Menu without a parent..." ) );
itsParent= parent; // But eventually we do want to know its parent.
}
Modal dialogs, being different, have different destruction code, and having menu objects in itsChildren list causes the non-rtti crash.
Anyhow a fix is coming, after more testing.