Trivial dialog-based application crashes with SIGSEGV Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
JeffG1
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Aug 02, 2017 6:39 pm

Trivial dialog-based application crashes with SIGSEGV

Post by JeffG1 »

Code::Blocks 16.01 with WxWidgets wxMSW 3.1.0 running on Windows 10

Using wxSmith to create a dialog and its code.

I have a problem with a dialog-based application crashing with a segmentation fault in wxWindowBase::InformFirstDirection(...) because when it calls GetSizer() to use as a pointer, that function is returning zero. This is line 871 in wincmn.cpp.

I have cut it down to the very minimum of wxDialog containing wxBoxSizer (horizontal) which contains a wxPanel containing a second wxBoxSizer (vertical).

Running without debug gives SIGSEGV with a termination code of -1073740771 in the call to wxSizer::Fit(...).

This is the code in the dialog constructor (generated by wxSmith):

Code: Select all

{
    wxBoxSizer* BoxSizer2;
    wxBoxSizer* BoxSizer1;

    Create(parent, wxID_ANY, _("Spine"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
    BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
    Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(137,566), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    BoxSizer2 = new wxBoxSizer(wxVERTICAL);
    Panel1->SetSizer(BoxSizer2);
    SetSizer(BoxSizer2);
    Layout();
    BoxSizer1->Add(Panel1, 1, wxALL, 5);
    SetSizer(BoxSizer1);
    BoxSizer1->Fit(this);				//<--- SEG FAULT IN THIS CALL
    BoxSizer1->SetSizeHints(this);
    }
    
P.S. If I construct a similar application, but frame based instead of dialog based, it's OK.

(This is my first post - I hope I have supplied enough information.)
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Trivial dialog-based application crashes with SIGSEGV

Post by ONEEYEMAN »

Hi,
Can you compile and run "dialogs" sample provided with wxWidgets?
Also, what is you compiler version and flavor?
And finally - how did you build the library and the application? The options for building the application must match the options for building the library.

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Trivial dialog-based application crashes with SIGSEGV

Post by PB »

I have never used wxSmith, is it really the verbatim code produced by it? Aside from the code being very difficult to read, this looks suspicious to me

Code: Select all

Panel1->SetSizer(BoxSizer2);
SetSizer(BoxSizer2);
One sizer being assigned to two different windows does not seem right...
JeffG1
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Aug 02, 2017 6:39 pm

Re: Trivial dialog-based application crashes with SIGSEGV

Post by JeffG1 »

Thanks for your replies. Sorry for any delay in replying, but I was expecting an email when my initial post got through moderation, and it never came.

@oneeyeman: Yes, I built the dialogs sample using the command line - by the way it's a pity that none of the examples have Code:Blocks project files (.cbp). When I tried to run it, I got the message that wxbase30u_gcc_custom.dll was not found. Compiler and version is minGW32: gcc 4.9.2 (32-bit).
I built both release and debug versions of wxWidgets with UNICODE=1. I did not specify MONOLITHIC (not sure what that does).

@pb: Yes, I have not changed any of the code generated by wxSmith. I used wxSmith because I am used to using a GUI editor in Visual C++, and it's built into Code::Blocks. The other editor (wxFormBuilder) is apparently free-standing so I didn't take time looking into how to use that.

I don't know how the code could be made easier to read - it seems to be doing what it has to do. I agree that the two calls to SetSizer for BoxSizer2 look odd, but I don't understand why they are there, and whether it's causing the problem.

I look forward to any further input you can give.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Trivial dialog-based application crashes with SIGSEGV

Post by doublemax »

Yes, the code wxSmith generated is just wrong.

I tested with this code and it worked (slightly modified to make it compile):

Code: Select all

class MyDialog : public wxDialog
{
public:
  MyDialog( wxWindow *parent )
  {
    wxBoxSizer* BoxSizer2;
    wxBoxSizer* BoxSizer1;

    Create(parent, wxID_ANY, _("Spine"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));

    BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);

    BoxSizer2 = new wxBoxSizer(wxVERTICAL);
    wxPanel *Panel1 = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(137,566), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    Panel1->SetSizer(BoxSizer2);

    //SetSizer(BoxSizer2);
    //Layout();

    BoxSizer1->Add(Panel1, 1, wxALL, 5);
    SetSizer(BoxSizer1);

    BoxSizer1->Fit(this);
    BoxSizer1->SetSizeHints(this);
  }
};
Use the source, Luke!
JeffG1
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Aug 02, 2017 6:39 pm

Re: Trivial dialog-based application crashes with SIGSEGV

Post by JeffG1 »

Many thanks! I just commented out the two lines that you did, and it compiled and ran successfully. So that comes down to a problem with wxSmith generating spurious code. The declaration of Panel1 in "my" code appeared to be missing but it is in the header file.

Thanks everyone for your help - I will now see if I can get the full project to work.

It looks like a bug needs to be reported to wxSmith but looking at how the bug tracker works, it's way beyond me. I don't even know what a patch is - some Linux thing I guess :)
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Trivial dialog-based application crashes with SIGSEGV

Post by doublemax »

Which bug tracker, http://trac.wxwidgets.org/ ? That's only for wxWidgets itself.

wxSmith is not a part of wxWidgets. Actually i don't even know if it's still under active development.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Trivial dialog-based application crashes with SIGSEGV

Post by ONEEYEMAN »

Hi,
There are bunch of RAD tool you can use with wxWIdgets. Some are free and some are not.
If something that you want to use is free - it doesn't mean its bad.

I'm very successfully using wxGlade (free version) and am very satisfied with it. It is still under active development and it generates the code that can be easily understood and followed.

I know there is wxFormBuilder, which is also a free tool. I'm sure it good as well.

Try to get more tools, see if you can get a hold of them by generating different GUI layouts and leave one to use.

Thank you.
JeffG1
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Aug 02, 2017 6:39 pm

Re: Trivial dialog-based application crashes with SIGSEGV

Post by JeffG1 »

Thanks for the info. Can I incorporate wxGlade into Code::Blocks as a plugin? Otherwise how would I use it? (I will go and look for myself of course - I don't expect to be spoon-fed! :))
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Trivial dialog-based application crashes with SIGSEGV

Post by ONEEYEMAN »

Hi,
wxGlade is a standalone application written in {wx}Python.
You can try to download it and see or you can ask its maintainer on the mailing list if its possible to incorporate it anywhere.

You can also try to use wxFormBuilder or wxCrafter. I know the latter is incorporated in CodeLite (Disclaimer - I'm not connected in any way to either software) and I know wxFormBuilder is/was incorporated somewhere as well (if memory serves me right).

wxCrafter is a closed source software, wxGlade/wxFormBuilder I believe are open source one.
However you should check their website to be absolutely sure.

Like I said - not all free software is bad. ;-)

Thank you.
JeffG1
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Aug 02, 2017 6:39 pm

Re: Trivial dialog-based application crashes with SIGSEGV

Post by JeffG1 »

Postscript: I eventually found out that the cause of the incorrect code generation was that in the attributes for Panel1, actual values for Width and Height were set, instead of the Default Size box being checked. Setting default size fixed the problem

Because it's a wxSmith thing, I have discussed and reported this in the Code::Blocks forum. Posting here just for information.
Post Reply