Problem with MDI on Mac

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
yaront
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Jan 28, 2007 12:01 pm

Problem with MDI on Mac

Post by yaront »

HI,

Quoting from the Mac/Carbon/Mdi.cpp:

Code: Select all

void wxMDIParentFrame::AddChild(wxWindowBase *child)
{
    if ( !m_currentChild )
    {
        m_currentChild = wxDynamicCast(child, wxMDIChildFrame);

        if ( m_currentChild && IsShown() && !ShouldBeVisible() )
        {
            // we shouldn't remain visible any more
            wxFrame::Show(false);
            m_shouldBeShown = true;
        }
    }

    wxFrame::AddChild(child);
}
If you look carefully, before the child is really inserted it becomes the currentChild. If the window is visible and there are no non-MDI children (ShouldBeVisible() is false) the MDI parent is hidden.

When it is hidden, for some reason it gets an activate event which causes it to activate the currentChild. But the currentChild's activates relies on having it's parent set.
As you can see from the code this happens only at the end of the function.

Eventually I crash on the activate code.
I copied most of my code form the MDI sample with a small modification.

Can anyone help with this? Is this a bug?
Yaron Tadmor
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra »

I've been using wxMDIParentFrame/wxMDIChildFrame on Mac for sometime with no problems in relation to this building it with every version of wxWidgets from 2.6.3 to 2.8.1.

Do you for some reason Show() the MDI child frame before adding it?

What version of wxWidgets are you using?

Can you reproduce this in the mdi sample?

And last, but not least, why is your code actually crashing? What are you doing in OnActivate() to make it crash? A call stack would be helpful.

Something else you can try is adding a breakpoint in the wxActivateEvent constructor, and tracing down what triggers the activate event.
yaront
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Jan 28, 2007 12:01 pm

Post by yaront »

Hi,

Thanx for the help.
As for you questions...

I'm using version 2.1.8.

I didn't test the MDI sample code, since I have not had time to create an xCode project for it yet.
By the way, is there an easy and fast way to create xCode projects for the samples?

As for what I'm doing:
1) Create the MDI parent.
2) Hide it and set it as top window.
3) Creaet the MDI child. The crash is somewhere in down the stack from the child's d-tor. (see below).

What is going on there is this (this is pretty much the stack trace):
1) MDI child's c-tor calls MDI parent's AddChild().
2) MDI parent's AddChild sets the m_currentChild member, and decides to call wxFrame::Show(fals) to hide the MDI parent.
3) The hiding causes a deactivate event to be sent to the parent.
4) MDI parent's deactivate code check m_currentChild and if it's not NULL calls its deactiavet code.
5) MDI child's deactivate code accesses the m_parent member, which is NULL at this point. It is only set to the MDI parent in AddChild() AFTER the hide is taking place.

So I fail on the assert of m_parent!=NULL in MDI child's deactivate code. If I ignore the assert the code crashes later on.

I hope this is clear enough. I'm not near my Mac now so I can't give you the exact function names, but I think you can figure them out. I'll repost again when I get to the office.
Yaron
yaront
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Jan 28, 2007 12:01 pm

Post by yaront »

Well... this is very strange.

To work around this for now, I just made the window visible for the time being.
I continued to do some other changes to the windows.

I then changed it back to hide the window, and it didn't crash. The code wasn't trying to hide the already hidden MDI parent anymore.

So I guess this is solved as a crash, but I still don't understand what I did wrong, or what I changed that made it go away

Yaron
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

I'm using version 2.1.8.
I hope you mean 2.8.1? :? otherwise it' time for an update! ;)
yaront
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Jan 28, 2007 12:01 pm

Post by yaront »

he he.... yes 2.8.1 :?
Post Reply