Bind()/Connect() cause an SIGILL

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
AFailWorthFinding
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Aug 13, 2019 12:24 pm

Bind()/Connect() cause an SIGILL

Post by AFailWorthFinding » Tue Aug 13, 2019 12:57 pm

Hi everyone.
I have a problem with an SIGILL(Program received signal SIGILL, Illegal instruction.) in my code in the line consolidateButton->Bind(...)

Code: Select all

wxVisirConsolidateFrame::wxVisirConsolidateFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(wxVisirConsolidateFrame)
    wxMenu* Menu1;
    wxMenu* Menu2;
    wxMenuBar* MenuBar1;
    wxMenuItem* MenuItem1;
    wxMenuItem* MenuItem2;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(400,600));
    consolidateButton = new wxButton(this, ID_BUTTON1, _("Consolidate"), wxPoint(40,432), wxSize(320,120), 0, wxDefaultValidator, _T("ID_BUTTON1"));
    notificationText = new wxStaticText(this, ID_STATICTEXT1, _("Notifications"), wxPoint(144,32), wxSize(104,24), wxALIGN_CENTRE|wxNO_BORDER, _T("ID_STATICTEXT1"));
    notificationList = new wxListBox(this, ID_LISTBOX1, wxPoint(32,64), wxSize(336,368), 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);
    dateEntry = new wxTextEntryDialog(this, wxEmptyString, _("Input Text"), wxEmptyString, wxOK|wxCANCEL|wxCENTRE|wxWS_EX_VALIDATE_RECURSIVELY, wxDefaultPosition);

    consolidateButton->Bind(wxEVT_BUTTON,&wxVisirConsolidateFrame::OnconsolidateButtonClick,this);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&wxVisirConsolidateFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&wxVisirConsolidateFrame::OnAbout);
    //*)
}
Im really new to wxWidgets and I'm using the wxSmith GUI-builder with Code::Blocks 17.12. The builder creates a Connect()-function instead of the Bind()-function but in both cases it is possible to recieve a SIGILL, but it doesn't always do.
Does someone have an idea how to solve this fail?
Thanks everyone

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2020
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bind()/Connect() cause an SIGILL

Post by PB » Tue Aug 13, 2019 2:02 pm

The code you posted looks OK to me (well, at least from "should not crash" viewpoint).

So, assuming there is not something wrong with your build, the cause should be in the event handler. However, creating a modal dialog in the middle the ctor looks odd...

What does the backtrace after the crash say?

Stripping the code down to the bare minimum and see if it helps could be useful, I would start with removing the wxTextEntryDialog creation.

AFailWorthFinding
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Aug 13, 2019 12:24 pm

Re: Bind()/Connect() cause an SIGILL

Post by AFailWorthFinding » Tue Aug 13, 2019 2:12 pm

Hi PB.

I'm only using the minimum of code.

The build is not the problem, it builds without any error.

If I'm debugging it sometimes throws an SIGILL like I postet in the brackets. I only get the line of the problem from the debugger in addition. So I'm afraid I can't provide more informations.

If you can tell me how I could get more informations(maybe the backtrace, don't know it) please tell me so I can give more information.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2020
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bind()/Connect() cause an SIGILL

Post by PB » Tue Aug 13, 2019 3:27 pm

AFailWorthFinding wrote:
Tue Aug 13, 2019 2:12 pm
I'm only using the minimum of code.
The code you posted could be reduced A LOT. Often, one will find the issue while gradually stripping down the code, when it starts to work once you the remove problematic part.
AFailWorthFinding wrote:
Tue Aug 13, 2019 2:12 pm
The build is not the problem, it builds without any error.
I was referring to whether your build is not somehow corrupted, leading to unexpected behaviour. It does not happen often but it does happen. You can run the bundled samples using to see if they do not have an issue as well.

Anyway, considering the nature of your issue, my guess would be that you are corrupting memory somewhere, which leads to seemingly random crashes. The error seems like it too, as it looks as you are attempting to execute code from a memory address where you should not.

You did not mention your platform but based on the error it seems to be Linux which I do not use, so I cannot offer a specific help.

My advice (I assume you are using Debug build with asserts and runtime checks on) would be (1) to review the code by hand to see there is no obvious bug, (2) make sure you have all the compiler warnings turned on to give you a hint about a potential problem, and (3) start stripping down your code till the issue disappears.

alys666
I live to help wx-kind
I live to help wx-kind
Posts: 191
Joined: Tue Oct 18, 2016 2:31 pm

Re: Bind()/Connect() cause an SIGILL

Post by alys666 » Tue Aug 13, 2019 4:34 pm

for me, this code lines are questionable

Code: Select all

    
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&wxVisirConsolidateFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&wxVisirConsolidateFrame::OnAbout);
here a type converstion (wxObjectEventFunction) is dangerous. here any function can be assigned as event hook.
is this code automatically generated? and do this functions have proper header?
ubuntu 16.04, wxWidgets 3.0.4

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2020
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bind()/Connect() cause an SIGILL

Post by PB » Tue Aug 13, 2019 4:41 pm

Connect()s can be dangerous. But in this case:
  1. The code is generated by a tool which should ensure the event handler has the correct signature.
  2. The code was said to crash even when using Bind(); Bind() should not allow binding a method with an incorrect signature.
  3. The code crashes only sometimes.
But perhaps this still cannot be ruled out, unless the OP provides event handler definitions...

alys666
I live to help wx-kind
I live to help wx-kind
Posts: 191
Joined: Tue Oct 18, 2016 2:31 pm

Re: Bind()/Connect() cause an SIGILL

Post by alys666 » Tue Aug 13, 2019 4:52 pm

PB wrote:
Tue Aug 13, 2019 4:41 pm
Connect()s can be dangerous. But in this case:
  1. The code is generated by a tool which should ensure the event handler has the correct signature.
  2. The code was said to crash even when using Bind(); Bind() should not allow binding a method with an incorrect signature.
  3. The code crashes only sometimes.
But perhaps this still cannot be ruled out, unless the OP provides event handler definitions...
to check signature of a hook the tool must have full C++ parser(I highly doubt it has), and if tool is already sure about function, why it generates a type conversion??? at least that code looks strange. Imo.
ubuntu 16.04, wxWidgets 3.0.4

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2020
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bind()/Connect() cause an SIGILL

Post by PB » Tue Aug 13, 2019 6:44 pm

alys666 wrote:
Tue Aug 13, 2019 4:52 pm
to check signature of a hook the tool must have full C++ parser(I highly doubt it has), and if tool is already sure about function, why it generates a type conversion??? at least that code looks strange. Imo.
I do not use wxSmith but tools like that have no need for a C++ parser. I believe one just selects an event and the tool generates the method declaration and definition, with a signature matching the event. IMO Connect() and not Bind() is used because Connect() is compatible with both wxWidgets 2.8 and 2.9+. I have no idea why wxSmith always uses wxObjectEventFunction instead of e.g. here wxCommandEventHandler but this still works so it should not be an issue here.

AFailWorthFinding
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Aug 13, 2019 12:24 pm

Re: Bind()/Connect() cause an SIGILL

Post by AFailWorthFinding » Wed Aug 14, 2019 7:38 am

Thanks for your tips.
alys666 wrote:
Tue Aug 13, 2019 4:34 pm
is this code automatically generated?
yes all the code provided was generated automatically.
PB wrote:
Tue Aug 13, 2019 3:27 pm
You did not mention your platform
I'm using Windows 7 with the TDM-GCC compiler.

I finally found the real cause of the issue. It's the line

Code: Select all

dateEntry = new wxTextEntryDialog(this, wxEmptyString, _("Input Text"), wxEmptyString, wxOK|wxCANCEL|wxCENTRE|wxWS_EX_VALIDATE_RECURSIVELY, wxDefaultPosition);
that corrupts memory. Does someone have an idea what I have to change in the line so that I can keep the wxTextEntryDialog?

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2020
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bind()/Connect() cause an SIGILL

Post by PB » Wed Aug 14, 2019 8:25 am

AFailWorthFinding wrote:
Wed Aug 14, 2019 7:38 am
Does someone have an idea what I have to change in the line so that I can keep the wxTextEntryDialog?
I would not create the dialog in the constructor. I have no idea what you need the dialog for but modal dialogs are not commonly created on the heap and kept, they are usually created on the stack when needed, like this

Code: Select all

void SomeFrame::OnSomeEvent(...)
{
   SomeDialog dlg(this,...)

   if ( dlg.ShowModal() != wxID_OK )
     return;

   do something with the information obtained from dialog
}
But perhaps you do not even need wxTextEntryDialog and can just call one of the utility functions:
https://docs.wxwidgets.org/trunk/group_ ... ialog.html

Post Reply