Opened 3 years ago

Closed 22 months ago

#13622 closed defect (fixed)

wxButton with wxBU_NOTEXT and wxBU_EXACTFIT crashes in OSX wxCocoa

Reported by: johnr Owned by:
Priority: normal Milestone:
Component: wxOSX-Cocoa Version: stable-latest
Keywords: wxButton wxBU_NOTEXT wxBU_EXACTFIT Cc:
Blocked By: Blocking:
Patch: no

Description

Combining wxButton with wxBU_NOTEXT and wxBU_EXACTFIT crashes in OSX wxCocoa.

To reproduce, change widgets sample button.cpp line 467 to read

bbtn = new wxButton(this, ButtonPage_Button, wxString(),
                                wxDefaultPosition, wxDefaultSize, 
                                wxBU_NOTEXT | wxBU_EXACTFIT);

Run the sample in OSX.
Choose the button page
Select "Bitmap only" and "Fit exactly"
Deselect "Use wxBitmapButton"

Built on Snow Leopard with:
set arch_flags="-arch x86_64"

./../configure -with-osx_cocoa --disable-shared --disable-compat28 --enable-unicode CFLAGS="$arch_flags" CXXFLAGS="$arch_flags" CPPFLAGS="$arch_flags" LDFLAGS="$arch_flags" OBJCFLAGS="$arch_flags" OBJCXXFLAGS="$arch_flags" --with-libjpeg=builtin --with-libpng=builtin --with-regex=builtin --with-libtiff=builtin --with-zlib=builtin --with-expat=builtin

Change History (4)

comment:1 Changed 3 years ago by johnr

FWIW I commented these lines in button_osx.cpp

    // FIXME: this hack is needed because we're called from
    //        wxBitmapButton::Create() with this style and we currently use a
    //        different wxWidgetImpl method (CreateBitmapButton() rather than
    //        CreateButton()) for creating bitmap buttons, but we really ought
    //        to unify the creation of buttons of all kinds and then remove
    //        this check
//    if ( style & wxBU_NOTEXT )
//    {
//        return wxControl::Create(parent, id, pos, size, style,
//                                 validator, name);
//    }

as this Create method does not create a peer.

and it did not crash whether I supplied wxString() or "some text" as the label.
If I supply a label then the label is still drawn despite the wxBU_TEXT flag but I ran out of time on that today.

comment:2 follow-up: Changed 3 years ago by vadz

Would you have the stack trace for the crash by chance?

comment:3 in reply to: ↑ 2 Changed 3 years ago by johnr

wxBU_NOTEXT and wxBU_EXACTFIT Replying to vadz:

Would you have the stack trace for the crash by chance?

No but here is another.
Only wxBU_NOTEXT is needed to reproduce this. wxBU_EXACTFIT is a furphy. The button is created without a peer as noted above.

#0	0x00000001001e5374 in wxWindow::DoGetSize(int*, int*) const at .../src/osx/window_osx.cpp:709
#1	0x000000010008d4a9 in wxWindowBase::GetSize() const ()
#2	0x00000001003a5771 in wxSizerItem::DoSetWindow(wxWindow*) ()
#3	0x00000001003a593f in wxSizerItem::wxSizerItem(wxWindow*, int, int, int, wxObject*) ()
#4	0x00000001003a5819 in wxSizerItem::wxSizerItem(wxWindow*, int, int, int, wxObject*) ()
#5	0x00000001000087bb in wxSizer::Add(wxWindow*, int, int, int, wxObject*) ()
#6	0x0000000100015743 in ButtonWidgetsPage::CreateContent() ()

comment:4 Changed 22 months ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [72896]) Make hack for button creation in wxOSX more robust.

Don't crash when creating a plain wxButton with wxBU_NOTEXT style. This
happened because we skipped creating the peer (real implementation) in this
case entirely on the assumption that we were creating a wxBitmapButton, but
this is not necessarily the case. So now test that the creation of the peer is
really disabled before skipping it (this required adding ShouldCreatePeer()
accessor).

Merging wxWidgetImpl::CreateButton() and CreateBitmapButton() (and the same
thing for toggle buttons) would still be a better solution but while it's
trivial to do for Cocoa, it isn't for Carbon. And we can't use a single
function for Cocoa but different functions for Carbon, so for now just
continue to use this hack.

Closes #13622.

Note: See TracTickets for help on using tickets.