wxPropertyGrid - button without toplevel?

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
vanarieleyen
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Aug 29, 2019 3:55 am

wxPropertyGrid - button without toplevel?

Post by vanarieleyen » Thu Sep 05, 2019 2:33 am

I have a wxPropertyGrid in a wxScrolledWindow, see below

Code: Select all

	
	rightColumn = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxSize(350, 400));
	
	wxScrolledWindow* scrollerBottom = new wxScrolledWindow(rightColumn, wxID_ANY);

	wxBoxSizer* sizerBottom = new wxBoxSizer(wxVERTICAL);

	pg = new wxPropertyGrid(scrollerBottom, wxID_ANY,
	                        wxDefaultPosition, wxSize(800,600),
	                        wxPG_SPLITTER_AUTO_CENTER |
	                        wxPG_DEFAULT_STYLE );
In another part of the code I populate the propertygrid:

Code: Select all

......
pg->AppendIn(prop, new wxFileProperty(label, x.first, x.second) );
......
The code works fine. I can select files in the property grid.

The problem that have is when closing the program.
Sometimes an error pops up that says:
wxWidgets Debug Alert
A debugging check in this application has failed.
../../src/msw/button.cpp(256): assert "parent" failed in GetLWParentIfNotBeingDeleted():
button without top level parent?
I guess it is related to the button in the wxFileProperty in the propertygrid because it only happens when I use the file selector from this property.

What could be the cause of this error?

User avatar
doublemax
Moderator
Moderator
Posts: 13985
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPropertyGrid - button without toplevel?

Post by doublemax » Thu Sep 05, 2019 5:21 am

Does this also happen in the "propgrid" sample?
Use the source, Luke!

vanarieleyen
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Aug 29, 2019 3:55 am

Re: wxPropertyGrid - button without toplevel?

Post by vanarieleyen » Thu Sep 05, 2019 6:54 am

I am not sure.

I would like to try it out but it is rather complicated when using mingw. Of course I can try it in Linux but that would not be of much use because the program I am making is for a win environment.

vanarieleyen
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Aug 29, 2019 3:55 am

Re: wxPropertyGrid - button without toplevel?

Post by vanarieleyen » Thu Sep 05, 2019 8:45 am

I have made a very minimal test case that also has this error:

here is the cpp file:

Code: Select all

/***************************************************************
 * Name:      propgridMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    Arie van Leyen ()
 * Created:   2019-09-05
 * Copyright: Arie van Leyen ()
 * License:
 **************************************************************/

#include "propgridMain.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(propgridFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
	short_f, long_f
};

wxString wxbuildinfo(wxbuildinfoformat format) {
	wxString wxbuild(wxVERSION_STRING);

	if (format == long_f ) {
#if defined(__WXMSW__)
		wxbuild << _T("-Windows");
#elif defined(__UNIX__)
		wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
		wxbuild << _T("-Unicode build");
#else
		wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
	}

	return wxbuild;
}

//(*IdInit(propgridFrame)
const long propgridFrame::ID_PANEL1 = wxNewId();
const long propgridFrame::idMenuQuit = wxNewId();
const long propgridFrame::idMenuAbout = wxNewId();
const long propgridFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(propgridFrame,wxFrame)
	//(*EventTable(propgridFrame)
	//*)
END_EVENT_TABLE()

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

	Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
	Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(256,192), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
	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);

	Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&propgridFrame::OnQuit);
	Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&propgridFrame::OnAbout);
	//*)

	this->SetSize(500, 500);
	pg = new wxPropertyGrid(Panel1, wxID_ANY,
	                        wxDefaultPosition, wxSize(400,400),
	                        wxPG_SPLITTER_AUTO_CENTER |
	                        wxPG_DEFAULT_STYLE );
	pg->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );

	pg->Append( new wxFileProperty("FileProperty", wxPG_LABEL, wxEmptyString) );
}

propgridFrame::~propgridFrame() {
	//(*Destroy(propgridFrame)
	//*)
}

void propgridFrame::OnQuit(wxCommandEvent& event) {
	Close();
}

void propgridFrame::OnAbout(wxCommandEvent& event) {
	wxString msg = wxbuildinfo(long_f);
	wxMessageBox(msg, _("Welcome to..."));
}

and the header:

Code: Select all

/***************************************************************
 * Name:      propgridMain.h
 * Purpose:   Defines Application Frame
 * Author:    Arie van Leyen ()
 * Created:   2019-09-05
 * Copyright: Arie van Leyen ()
 * License:
 **************************************************************/

#ifndef PROPGRIDMAIN_H
#define PROPGRIDMAIN_H

//(*Headers(propgridFrame)
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/panel.h>
#include <wx/statusbr.h>
//*)

#include <wx/propgrid/propgrid.h>

class propgridFrame: public wxFrame
{
    public:

        propgridFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~propgridFrame();

        wxPropertyGrid *pg;

    private:

        //(*Handlers(propgridFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        //*)

        //(*Identifiers(propgridFrame)
        static const long ID_PANEL1;
        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        //*)

        //(*Declarations(propgridFrame)
        wxPanel* Panel1;
        wxStatusBar* StatusBar1;
        //*)

        DECLARE_EVENT_TABLE()
};

#endif // PROPGRIDMAIN_H

This minimal example does its best to show the error (each time)

To reproduce is:
Start the program
Select a file in the property grid
Close the program

vanarieleyen
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Aug 29, 2019 3:55 am

Re: wxPropertyGrid - button without toplevel?

Post by vanarieleyen » Thu Sep 05, 2019 8:54 am

Just a small follow up:

I just did a test by first deleting 'pg' on program close.

This removes the error.

Could it be that the memory is not properly freed upon exit?
I thought that it would be automatically freed when the parent class is destroyed...
Last edited by vanarieleyen on Thu Sep 05, 2019 9:03 am, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 13985
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPropertyGrid - button without toplevel?

Post by doublemax » Thu Sep 05, 2019 8:57 am

Thanks. But when building and running this from Visual Studio, i don't get an error.

What type of image did you select?
Does it also happen if you cancel the file select?

Which wxWidgets version are you using?
Use the source, Luke!

User avatar
doublemax
Moderator
Moderator
Posts: 13985
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPropertyGrid - button without toplevel?

Post by doublemax » Thu Sep 05, 2019 9:01 am

vanarieleyen wrote:
Thu Sep 05, 2019 8:54 am
I just did a test by first deleting 'pg' on program close.

This removes the error.
Remove that again. pg is a child of Panel1, so it should be deleted automatically. There must be a different issue.
Use the source, Luke!

vanarieleyen
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Aug 29, 2019 3:55 am

Re: wxPropertyGrid - button without toplevel?

Post by vanarieleyen » Thu Sep 05, 2019 9:14 am

I am running wxWidgets 3.1.*
and it happens with any file that I select or pressing the cancel button.

Yes, it should automatically be freed but apparently it isn't.

For the time being I leave it in the destructor of the frame until the issue is solved.

Post Reply