RadioGroup stops working if lots of forms created/destroyed. Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Blingo
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue Dec 17, 2013 3:39 pm

RadioGroup stops working if lots of forms created/destroyed.

Post by Blingo »

Hi There

I've attached an application to reproduce. Maybe this is a more general issue but the title reflects what I am seeing.

Windows 7, 64 bit, 32 bit python and wxpython: wx-2.8-msw-unicode

The radiogroups stopped working in my 50k LOC application (a serious issue since they are used for save dialogues etc), seemingly (at first) randomly.

I whittled the problem down to the attached application. The main file to look at is MainFrame.py. To reproduce:

1- Set MAXITERS very high (eg 10000)
2- Run app and click the button. Eventually an exception will be thrown (wx._core.PyAssertionError (probably from handle limit exceeded))
3- Note the number that this occurred at (for me 4994) and change MAXITERS to just less than this (for me 4900)
4- Rerun the application.
5- Click the button. Each time MAXITERS is reached click the button again.
6- On second click a radio group will appear. Change the value and then close the dialogue.
7- The selected radio button will print to the stdout. Note whether it is the same or not to that selected.
8- Repeat 5-7. Eventually (for me about 5 times) the printed radio selection will not equal to that selected.

These numbers here are high but in my app the equivalent MAXITERS loop is about 4 and I'll see the issue after about 10 runs.

Perhaps something to do with available handles but the 10k limit is never exceeded (at least according to ProcExp), the exception is never thrown and each form is subsequently destroyed.

Thanks in advance
Attachments
rgrpTest.zip
(1.88 KiB) Downloaded 93 times
Last edited by Blingo on Fri May 22, 2015 7:27 pm, edited 1 time in total.
Blingo
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue Dec 17, 2013 3:39 pm

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by Blingo »

Just noticed that the following lines are the wrong way round:
t.Destroy()
print str(t.get()+1)

However, I'm nearly sure this is not what is causing the issue (it's definitely not like this in my main application). Can't verify though because the issue does not reproduce on my much faster i7, win8 home computer for either case. Reproducable on my work computer.
Blingo
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue Dec 17, 2013 3:39 pm

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by Blingo »

OK, I retested this in work with the above correction in place and the issue still occurs. My work computer is an i5-2450M 8GB.

Take it no one else could reproduce?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by doublemax »

I would need a sample in C++ that shows the problem. And my understanding of Python is not good enough to translate it myself.
Use the source, Luke!
Blingo
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue Dec 17, 2013 3:39 pm

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by Blingo »

OK. Will see what I can do. Give me a couple of days.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by doublemax »

However, i'm 90% sure that's a wxPython related problem and that it won't happen in a C++ version.
Use the source, Luke!
Blingo
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue Dec 17, 2013 3:39 pm

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by Blingo »

HI there. I recreated in C++ and the problem happens here too.
Blingo
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue Dec 17, 2013 3:39 pm

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by Blingo »

Sorry fail didn't attached. I removed the 2.8 runtimes in case size related/.
Attachments
rgrpTest.zip
(172.91 KiB) Downloaded 87 times
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by PB »

It would be MUCH better if you provided just a single self-compilable file instead of whole project specific to an IDE, compiler and wxWidgets version and build, which can be easily tested by anyone. Patch to the minimal sample is usually the best, i.e. the same way one would do that if filling a bug report.

This is my attempt to create such a piece of code, it being as concise as possible while staying as close as possible the original. It appears to works for me but I am on wxWidgets 3.1 and use MSVC. Perhaps someone else can try it though. You should also try it to see if it fails on your computer as expected.

Code: Select all

#include <wx/wx.h>

class Dialog : public wxDialog 
{	
	protected:
		wxRadioBox* m_radioBox1;	
	public:		
	    Dialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 108,149 ), long style = wxDEFAULT_DIALOG_STYLE );	
        int getRadioSelection();        
};

Dialog::Dialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	wxBoxSizer* bSizer2;
	bSizer2 = new wxBoxSizer( wxVERTICAL );
	
	wxString m_radioBox1Choices[] = { wxT("0"), wxT("1"), wxT("2"), wxT("3") };
	int m_radioBox1NChoices = sizeof( m_radioBox1Choices ) / sizeof( wxString );
	m_radioBox1 = new wxRadioBox( this, wxID_ANY, wxT("wxRadioBox"), wxDefaultPosition, wxDefaultSize, m_radioBox1NChoices, m_radioBox1Choices, 1, wxRA_SPECIFY_COLS );
	m_radioBox1->SetSelection( 0 );
	bSizer2->Add( m_radioBox1, 0, wxALL, 5 );
	
	this->SetSizer( bSizer2 );
	this->Layout();
	
	this->Centre( wxBOTH );
}

int Dialog::getRadioSelection()
{
    return m_radioBox1->GetSelection();
}

class Frame : public wxFrame 
{
	protected:
		bool m_switch;
        wxButton* m_button1;
		wxTextCtrl* m_textCtrl1;				
		void OnClose( wxCloseEvent& event );
		void m_button1OnButtonClick( wxCommandEvent& event );
			
	public:		
		Frame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("wxWidgets Application Template"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 186,186 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
		~Frame();	
};

Frame::Frame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	wxBoxSizer* bSizer1;
	bSizer1 = new wxBoxSizer( wxVERTICAL );
	
	m_button1 = new wxButton( this, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer1->Add( m_button1, 0, wxALL, 5 );
	
	m_textCtrl1 = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	bSizer1->Add( m_textCtrl1, 0, wxALL, 5 );
	
	this->SetSizer( bSizer1 );
	this->Layout();

    m_switch = true;
	
	// Connect Events
	this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( Frame::OnClose ) );
	m_button1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( Frame::m_button1OnButtonClick ), NULL, this );
}

Frame::~Frame()
{	
	this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( Frame::OnClose ) );
	m_button1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( Frame::m_button1OnButtonClick ), NULL, this );	
}


void Frame::OnClose(wxCloseEvent&)
{
    Destroy();
}

void Frame::m_button1OnButtonClick( wxCommandEvent&)
{
    const unsigned int MAXITERS = 9900;

    if (m_switch) {
        for (unsigned int i=0; i<MAXITERS; ++i) {
            Frame* a = new Frame(this);
            delete a;
        }
        m_textCtrl1->SetValue(wxString(wxT("Finished")));
    }
    else {
        Dialog* b = new Dialog(this);
        b->ShowModal();        
        m_textCtrl1->SetValue(wxString::Format(wxT("%d"), b->getRadioSelection()));
        delete b;
    }
    m_switch = !m_switch;
}


class MyApp : public wxApp
{
public:	
	virtual bool OnInit()
	{
        (new Frame(NULL))->Show();
        return true;
	}
};
IMPLEMENT_APP(MyApp)
EDIT
For whatever it is worth, I tried the code above with wxWidgets 2.8.12 (static ANSI debug build compiled with MSVC 2008 express) and sometimes after an iteration has been run, the number displayed in the text control doesn't match the one selected in the radio box. It should be easy to debug but 2.8 branch is not officially supported anymore... On the other hand, I just may have been lucky with wxWidgets 3 and the issue may still be there.
Blingo
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue Dec 17, 2013 3:39 pm

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by Blingo »

Apologies for the code. I haven't been near C++ for a while and had spent most of the day trying to set up my environment and get the wxwidgets FW built. No excuse I suppose except my laziness. I didn't think the relevant files were IDE (or compiler) specific though.

Anyway, I'm glad though that someone else was able to see the problem. It's not just a different radio choice being returned, it seems that once the component has broken it will just return the default index zero. At least that's what I was seeing.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by doublemax »

I was able to reproduce it in 2.8.12, but not with 3.0.2.

I don't know which code change might have fixed the problem, maybe this one:
http://trac.wxwidgets.org/changeset/69682/svn-wx
Use the source, Luke!
Blingo
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue Dec 17, 2013 3:39 pm

Re: RadioGroup stops working if lots of forms created/destroyed.

Post by Blingo »

Thanks. I'll probably have to consider porting to 3.0 at some stage. Tried this quickly before and it seemed messy.
Post Reply