Claification on Sizers Error Topic is solved

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
philm
Experienced Solver
Experienced Solver
Posts: 88
Joined: Fri Dec 18, 2015 4:46 am

Claification on Sizers Error

Post by philm »

Hello everyone, I recently updated to the newest version of wxwidgets 3.1.

However, I am currently getting some usual errors with my sizers. Previously, I did not get these errors in 3.0.1. Looking through the documentation of sizers, I can't seem to figure out what is wrong.

I am adding sizers to my form and I am getting an error called:

"../src/common/wincmn.cpp(2471): assert ""!m_containingSizer"" failed in SetContainingSizer(): Adding a window already in a sizer, detach it first!"

This occurs at a line that I will be indicating on the code below. I have been looking through the examples and documentation and I can't seem to figure out why this error exists. I don't notice anything too different that I am doing. The only thing different from my perspective is that I am initilizing the widgets global to the class and then calling the Create function and then passing it into the add function of the sizer.

Code: Select all

    wxFont *font = new wxFont(8.5, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
    
    wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer *intermediateSizer = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer *footerSizer1 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer *footerSizer2 = new wxBoxSizer(wxHORIZONTAL);

    _outputConsole->Create(this, wxID_ANY, wxEmptyString, wxPoint(12, 12), wxSize(373, 98), wxTE_MULTILINE);
    _outputConsole->SetFont(*font);
    _outputConsole->Enable(false);
    
    _inputConsole->Create(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(373, 98), wxTE_MULTILINE);
    _inputConsole->SetFont(*font);
    _inputConsole->RemoveChild(this);
    
    wxButton *clearInputButton = new wxButton(this, generalFrameButton::ID_BUTTON1, "Clear Input", wxPoint(12, 242), wxSize(75, 23));
    clearInputButton->SetFont(*font);
    
    wxButton *clearOutputButton = new wxButton(this, generalFrameButton::ID_BUTTON2, "Clear Output", wxPoint(93, 242), wxSize(75, 25));
    clearOutputButton->SetFont(*font);
    
    wxButton *evaluateButton = new wxButton(this, wxID_OK, "Evaluate", wxPoint(310, 242), wxSize(75, 23));
    evaluateButton->SetFont(*font);
    
    footerSizer2->Add(evaluateButton, 0, wxCENTER | wxALL, 6);
    
    footerSizer1->Add(clearInputButton, 0, wxCENTER | wxALL, 6);
    footerSizer1->Add(clearOutputButton, 0, wxCENTER | wxTOP | wxBOTTOM | wxRIGHT, 6);
    
    intermediateSizer->Add(footerSizer1, 0, wxALIGN_LEFT);
    intermediateSizer->Add(137, 0, 0);
    intermediateSizer->Add(evaluateButton, 0, wxCENTER);
    
 //   topSizer->Add(_outputConsole, wxSizerFlags(0).Border(wxALL, 6));
    topSizer->Add(_inputConsole, 0, wxLEFT | wxRIGHT | wxBOTTOM, 6); // The error is here!
    topSizer->Add(0, 20, 0);
    topSizer->Add(intermediateSizer);
    
    SetSizerAndFit(topSizer);
On the line above the one that vae marked, I am getting another error. At first the function was:

Code: Select all

topSizer->Add(_outputConsole, 0, wxCENTER| wxALL, 6);
I tried changing it to the recommended method but I am getting the same error which was about the sizer couldn't horizontal center a horizontal sizer (As a side note, I uncommented the line out and I am no longer getting the error. So maybe it will pop up back soon)
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Claification on Sizers Error

Post by ONEEYEMAN »

Hi,
Do you have 2 issues with you code or just one?
An assert message is very clear - you are trying to add a window/sizer to a sizer and this same window/sizer already has been added to that sizer. Something like:

outSizer->Add( my_widget.... );
outSizer->Add( my_widget.... );

Please check you code that this thing is not happenning.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Claification on Sizers Error

Post by doublemax »

Code: Select all

footerSizer2->Add(evaluateButton, 0, wxCENTER | wxALL, 6);
[...]
intermediateSizer->Add(evaluateButton, 0, wxCENTER);
Adding evaluateButton to two sizers.

For the other error please post the assert message you're getting.
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Claification on Sizers Error

Post by PB »

<removed, I misread the OP>
philm
Experienced Solver
Experienced Solver
Posts: 88
Joined: Fri Dec 18, 2015 4:46 am

Re: Claification on Sizers Error

Post by philm »

Hello all,

I am getting two errors. The first being the sizer in a sizer. ANd the other being a formatting error. Interestingly, the formatting error has disappeared for now. So we are focusing on the sizer error.

Yes, it would seem that the error is in fact simple and saying that I have a sizer in a sizer. However, that is now the case. I posted the code of the function above. I made a comment that says where the error is occurring. For reference, here is the line where the error is:

Code: Select all

topSizer->Add(_inputConsole, 0, wxLEFT | wxRIGHT | wxBOTTOM, 6); // The error is here!
The only other place that _inputConsole is appearing is when I need to initialize it.

Also, when trying to figure to remove the message, I added in a line:

Code: Select all

_inputConsole->RemoveChild(this);
So far, this has had no effect on the operation of the function or the view of the dialog.

Interestingly, when I ignore assert message everything draws fine.
philm
Experienced Solver
Experienced Solver
Posts: 88
Joined: Fri Dec 18, 2015 4:46 am

Re: Claification on Sizers Error

Post by philm »

Ok so good news, I found the error, It lies on this line:

Code: Select all

     footerSizer2->Add(evaluateButton, 0, wxCENTER | wxALL, 6);
    
    footerSizer1->Add(clearInputButton, 0, wxCENTER | wxALL, 6);
    footerSizer1->Add(clearOutputButton, 0, wxCENTER | wxTOP | wxBOTTOM | wxRIGHT, 6);
    
    intermediateSizer->Add(footerSizer1, 0, wxALIGN_LEFT);
    intermediateSizer->Add(137, 0, 0);
    intermediateSizer->Add(evaluateButton, 0, wxCENTER);
I am surprised that V3.0.1 did not pick this up.

Evaluation button went to two different sizers.

As for the other error. I was able to get it on a different function call but the error is the same:

assert "!(flags & wxALIGN_RIGHT)" failed in DoInsert(): Horizontal alignment flags are ignored in horizontal sizers
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Claification on Sizers Error

Post by doublemax »

Code: Select all

assert "!(flags & wxALIGN_RIGHT)" failed in DoInsert(): Horizontal alignment flags are ignored in horizontal sizers
In the code you posted i see no wxALIGN_RIGHT anywhere.

However, the assert message is clear: In a horizontal boxsizer the flags wxALIGN_RIGHT and wxALIGN_LEFT make no sense.
In the same way the flags wxALIGN_TOP and wxALIGN_BOTTOM make no sense for vertical boxsizers.

If you get that assert, just remove the offending flag.
Use the source, Luke!
philm
Experienced Solver
Experienced Solver
Posts: 88
Joined: Fri Dec 18, 2015 4:46 am

Re: Claification on Sizers Error

Post by philm »

Yes, that was it! Thank you all for your assistance!
Post Reply