csteifel
csteifel

Reputation: 2934

wxWidgets Seg fault on close

My files look something like so:

main.cpp

...
bool SyncApp::OnInit(){
    SetTopWindow(new syncWindow(_("(S)FTP Automatic Sync")));
    GetTopWindow()->Show(true);
    return true;
}
...

syncwindow.h

#include <wx/wx.h>

class syncWindow : public wxFrame {
    public:
        syncWindow(wxString title) : wxFrame(NULL, -1, title)  { initialize(); }
    private:
        void initialize();
        wxTextCtrl * serverEntry;
};

syncwindow.cpp

void syncWindow::initialize(){
    serverEntry = new wxTextCtrl(this, wxID_ANY);

    this->AddChild(serverEntry);
}

For whatever reason whenever I close the window I get a segfault. If I don't add the serverEntry as a child to the window I don't get a segfault. I don't see why this is doing such a thing. I'm on CentOS 6, g++ 4.7 and wxGTK 2.8. Does anyone have any idea or a hint as to why this is happening?

Upvotes: 1

Views: 428

Answers (1)

Antonio
Antonio

Reputation: 20266

Since you specified the parent window when constructing your child, the link is already present and calling this->AddChild(serverEntry); will cause double free or similar error when you close the window. http://docs.wxwidgets.org/2.8/wx_wxwindow.html#wxwindowaddchild

wxWindow::AddChild

Adds a child window. This is called automatically by window creation functions so should not be required by the application programmer.

Notice that this function is mostly internal to wxWidgets and shouldn't be called by the user code.

Upvotes: 1

Related Questions