Discussion:
Crash in wxRibbonBar if clicking a menuitem of a ribbon-button of a minimzed panel
Tobias Abt
2014-04-28 09:09:50 UTC
Permalink
Hi,


there is a crash in wxRibbonBar that can easily be reproduced with the ribbon-sample.


(see attached image)


In the ribbon-sample:

1. make the frame so small that the Shapes-panel is minimized to a button.

2. click the Shapes-button, then click the "Other Polygon"-button

3. click any item of the menu

-> crash (or assertion first in debug mode)


Is this issue known or should I create a ticket for it? (or can somebody can reproduce it...)


Regards,

Tobi


wxWidgets: 3.0 (release)

Windows 7



### Assertion in Debug Mode:

---------------------------

wxWidgets Debug Alert

---------------------------

D:\build\wxWidgets-3.0.0-rc2\include\wx/object.h(160): assert "wxDynamicCast(ptr, T)" failed in wxCheckCast(): wxStaticCast() used incorrectly


Call stack:

[00] wxRibbonPanel::HideIfExpanded d:\build\wxwidgets-3.0.0-rc2\src\ribbon\panel.cpp:1103

[01] wxRibbonButtonBar::OnMouseUp d:\build\wxwidgets-3.0.0-rc2\src\ribbon\buttonbar.cpp:1162

[02] wxAppConsoleBase::HandleEvent d:\build\wxwidgets-3.0.0-rc2\src\common\appbase.cpp:612

[03] wxAppConsoleBase::CallEventHandler d:\build\wxwidgets-3.0.0-rc2\src\common\appbase.cpp:624

[04] wxEvtHandler::ProcessEventIfMatchesId d:\build\wxwidgets-3.0.0-rc2\src\common\event.cpp:1386

[05] wxEventHashTable::HandleEvent d:\build\wxwidgets-3.0.0-rc2\src\common\event.cpp:990

[06] wxEvtHandler::TryHereOnly d:\build\wxwidgets-3.0.0-rc2\src\common\event.cpp:1581

[07] wxEvtHandler::TryBeforeAndHere d:\build\wxwidgets-3.0.0-rc2\include\wx\event.h:3671

[08] wxEvtHandler::ProcessEventLocally d:\build\wxwidgets-3.0.0-rc2\src\common\event.cpp:1514

[09] wxEvtHandler::ProcessEvent d:\build\wxwidgets-3.0.0-rc2\src\common\event.cpp:1487

[10] wxEvtHandler::SafelyProcessEvent d:\build\wxwidgets-3.0.0-rc2\src\common\event.cpp:1605

[11] wxWindowBase::HandleWindowEvent d:\build\wxwidgets-3.0.0-rc2\src\common\wincmn.cpp:1526

[12] wxWindow::HandleMouseEvent d:\build\wxwidgets-3.0.0-rc2\src\msw\window.cpp:5516

[13] wxWindow::MSWHandleMessage d:\build\wxwidgets-3.0.0-rc2\src\msw\window.cpp:3016

[14] wxWindow::MSWWindowProc d:\build\wxwidgets-3.0.0-rc2\src\msw\window.cpp:3636

[15] wxWndProc d:\build\wxwidgets-3.0.0-rc2\src\msw\window.cpp:2725

[16] InternalCallWinProc

[17] UserCallWinProcCheckWow

[18] DispatchMessageWorker

[19] DispatchMessageW

[20] wxGUIEventLoop::ProcessMessage d:\build\wxwidgets-3.0.0-rc2\src\msw\evtloop.cpp:172
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-04-28 14:52:36 UTC
Permalink
On Mon, 28 Apr 2014 11:09:50 +0200 Tobias Abt wrote:

TA> ### Assertion in Debug Mode:
TA>
TA> ---------------------------
TA>
TA> wxWidgets Debug Alert
TA>
TA> ---------------------------
TA>
TA> D:\build\wxWidgets-3.0.0-rc2\include\wx/object.h(160): assert
TA> "wxDynamicCast(ptr, T)" failed in wxCheckCast(): wxStaticCast() used
TA> incorrectly
TA>
TA>
TA> Call stack:
TA>
TA> [00] wxRibbonPanel::HideIfExpanded d:\build\wxwidgets-3.0.0-rc2\src\ribbon\panel.cpp:1103

I think this should be relatively simple to fix: the code here clearly
supposes that the parent is a wxRibbonPage, but apparently it's not always
necessarily the case. wxRibbonPage is, however, probably a grandparent (or
grand grandparent or ...) of this window, so the code would just need to be
updated to look for it upwards in the inheritance hierarchy.

If you can change it to behave like this and attach a patch (please see
http://trac.wxwidgets.org/wiki/HowToSubmitPatches) to the ticket, it would
be most welcome. If not, please open a ticket for this bug nevertheless, so
that it at least doesn't get lost.

Thanks,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Tobias Abt
2014-04-29 11:31:57 UTC
Permalink
Post by Vadim Zeitlin
TA>
TA> D:\build\wxWidgets-3.0.0-rc2\include\wx/object.h(160): assert
TA> "wxDynamicCast(ptr, T)" failed in wxCheckCast(): wxStaticCast() used
TA> incorrectly
TA>
TA>
TA>
TA> [00] wxRibbonPanel::HideIfExpanded d:\build\wxwidgets-
3.0.0-rc2\src\ribbon\panel.cpp:1103
I think this should be relatively simple to fix: the code here clearly supposes
that the parent is a wxRibbonPage, but apparently it's not always necessarily
the case. wxRibbonPage is, however, probably a grandparent (or grand
grandparent or ...) of this window, so the code would just need to be
updated to look for it upwards in the inheritance hierarchy.
I've created a ticket: http://trac.wxwidgets.org/ticket/16215
and I looked some more into it, and I don't get it: a wxRibbonPanel is cast to a wxRibbonPage, which according to the documentation are siblings. (and then the wxRibbonPage ist cast to its sibling wxRibbonBar)
Post by Vadim Zeitlin
If you can change it to behave like this and attach a patch (please see
http://trac.wxwidgets.org/wiki/HowToSubmitPatches) to the ticket, it
would be most welcome. If not, please open a ticket for this bug
nevertheless, so that it at least doesn't get lost.
Thanks,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-04-29 11:37:46 UTC
Permalink
On Tue, 29 Apr 2014 13:31:57 +0200 Tobias Abt wrote:

TA> I've created a ticket: http://trac.wxwidgets.org/ticket/16215
TA> and I looked some more into it, and I don't get it: a wxRibbonPanel is
TA> cast to a wxRibbonPage, which according to the documentation are
TA> siblings. (and then the wxRibbonPage ist cast to its sibling
TA> wxRibbonBar)

Sorry, I don't follow you here. Where does the documentation say that
they're siblings and where is wxRibbonPage cast to wxRibbonBar?

AFAIK wxRibbonPage is a container for wxRibbonPanels. So to get to it we
just need to go upwards the parent chain until we reach it. Have you tried
doing this?

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Tobias Abt
2014-04-29 14:01:27 UTC
Permalink
-----Ursprüngliche Nachricht-----
Im Auftrag von Vadim Zeitlin
Gesendet: Dienstag, 29. April 2014 13:38
Betreff: Re: AW: Crash in wxRibbonBar if clicking a menuitem of a ribbon-
button of a minimzed panel
TA> I've created a ticket: http://trac.wxwidgets.org/ticket/16215
TA> and I looked some more into it, and I don't get it: a wxRibbonPanel
TA> is cast to a wxRibbonPage, which according to the documentation are
TA> siblings. (and then the wxRibbonPage ist cast to its sibling
TA> wxRibbonBar)
Sorry, I don't follow you here. Where does the documentation say that
they're siblings and where is wxRibbonPage cast to wxRibbonBar?
http://docs.wxwidgets.org/trunk/classwx_ribbon_control.html: They all inherit from wxRibbonControl, or am I missing something?
void wxRibbonPanel::HideIfExpanded()
{
wxStaticCast(m_parent, wxRibbonPage)->HideIfExpanded();
}
From ribbon/page.cpp
void wxRibbonPage::HideIfExpanded()
{
wxStaticCast(m_parent, wxRibbonBar)->HideIfExpanded();
}

As I said, I don't understand what's going on here:
1. In wxRibbonButtonBar::OnMouseUp m_parent is a wxRibbonPanel (OK, call there is: wxStaticCast(m_parent, wxRibbonPanel)->HideIfExpanded();
2. then in wxRibbonPanel::HideIfExpanded m_parent is according to my debugger a wxFrame
3 . In wxRibbonPage::HideIfExpanded it is NULL, probably because of "wxCheckDynamicCast" somewhere in this whole wx-casting.
AFAIK wxRibbonPage is a container for wxRibbonPanels. So to get to it we
just need to go upwards the parent chain until we reach it. Have you tried
doing this?
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-04-29 17:27:08 UTC
Permalink
On Tue, 29 Apr 2014 16:01:27 +0200 Tobias Abt wrote:

TA> http://docs.wxwidgets.org/trunk/classwx_ribbon_control.html: They all
TA> inherit from wxRibbonControl, or am I missing something?

I thought you meant "siblings" at the window hierarchy level, not at the
C++ class hierarchy. Because we really care about the former and not the
latter here and wxRibbonPanel is contained in (and is not sibling of)
wxRibbonPage.

TA> >From ribbon/panel.cpp:
TA> void wxRibbonPanel::HideIfExpanded()
TA> {
TA> wxStaticCast(m_parent, wxRibbonPage)->HideIfExpanded();
TA> }
TA>
TA> >From ribbon/page.cpp
TA> void wxRibbonPage::HideIfExpanded()
TA> {
TA> wxStaticCast(m_parent, wxRibbonBar)->HideIfExpanded();
TA> }

Yes, this looks correct. Again, the window hierarchy is

wxRibbonBar -> wxRibbonPage -> wxRibbonPanel

TA> As I said, I don't understand what's going on here:
TA> 1. In wxRibbonButtonBar::OnMouseUp m_parent is a wxRibbonPanel (OK,
TA> call there is: wxStaticCast(m_parent, wxRibbonPanel)->HideIfExpanded();
TA> 2. then in wxRibbonPanel::HideIfExpanded m_parent is according to my
TA> debugger a wxFrame

Yes, and this is a problem (and not nesting of wxRibbonPanels as I
originally thought). Apparently the temporary expanded panels are created
as children of wxFrame for some reason and so casting parent to
wxRibbonPage clearly isn't a good idea for them.

The following diff

----------------------------------------------------------------------------
diff --git a/src/ribbon/panel.cpp b/src/ribbon/panel.cpp
index fd354bf..1e37b6c 100644
--- a/src/ribbon/panel.cpp
+++ b/src/ribbon/panel.cpp
@@ -1100,7 +1100,9 @@ wxRect wxRibbonPanel::GetExpandedPosition(wxRect panel,

void wxRibbonPanel::HideIfExpanded()
{
- wxStaticCast(m_parent, wxRibbonPage)->HideIfExpanded();
+ wxRibbonPage* const containingPage = wxDynamicCast(m_parent, wxRibbonPage);
+ if (containingPage)
+ containingPage->HideIfExpanded();
}

#endif // wxUSE_RIBBON
----------------------------------------------------------------------------

fixes the problem, and while I don't like it at all, it's better than
crashing, so I'll commit this if nobody else has any better suggestions.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Loading...