Ribbon buttons + dialogs = crashes

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
User avatar
tehKaiN
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 25, 2017 7:09 pm
Location: Poland
Contact:

Ribbon buttons + dialogs = crashes

Post by tehKaiN »

Hi there,

So I'm wxWidgeting since about 2 weeks and although this library is amazing, I have some problems. Since I haven't got my answer from IRC today, I'll try here.

I've created sample code with simple ribbon and button event handler, which should spawn some simple dialog. When I click the ribbon button, the app crashes hard. Code is compiled using newest TDM and self-built wxWidgets 3.0.3 in static, release mode.

Code: Select all

#include <wx/wx.h>
#include <wx/ribbon/bar.h>
#include <wx/ribbon/buttonbar.h>
#include <wx/artprov.h>

typedef enum {
	idRibbonOnlineConnect = wxID_HIGHEST + 1,
	idRibbon,
	idRibbonControlPage,
	idConnectDlg,
} windowId;

class cRibbon: public wxRibbonBar {
	public:
		cRibbon(wxWindow *pParent);
};

cRibbon::cRibbon(wxWindow *pParent):
	wxRibbonBar(
		pParent, idRibbon, wxDefaultPosition, wxDefaultSize,
		wxRIBBON_BAR_FLOW_HORIZONTAL | wxRIBBON_BAR_SHOW_PAGE_LABELS |
		wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS | wxRIBBON_BAR_SHOW_TOGGLE_BUTTON
	)
{
	// 'Control'  page general layout
	wxRibbonPage *pPageControl = new wxRibbonPage(this, idRibbonControlPage, "Control");
	wxRibbonPanel *pPanelOnline = new wxRibbonPanel(
		pPageControl, wxID_ANY, "On-line mode", wxNullBitmap,
		wxDefaultPosition, wxDefaultSize, wxRIBBON_PANEL_NO_AUTO_MINIMISE
	);
	wxRibbonButtonBar *pOnlineBar = new wxRibbonButtonBar(pPanelOnline);
	pOnlineBar->AddButton(
		idRibbonOnlineConnect, "Connect",
		wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(48,48))
	);
	Realize();
}

class MyApp: public wxApp
{
  public:
      virtual bool OnInit();
};

extern class MyApp *g_pApp;

class MyFrame: public wxFrame
{
  public:
    MyFrame();

    wxPanel *m_pCont; ///< Main widget container.
		cRibbon *m_pRibbon;
		void onTestBtn(wxRibbonButtonBarEvent &evt);
};

class tExampleDlg: public wxDialog {
	public:
		tExampleDlg(wxWindow *pParent):
			wxDialog(pParent, idConnectDlg, "Select port", wxDefaultPosition, wxSize(400, 200))
		{
			new wxButton(this, wxID_ANY, "dupa");
			Centre();
		}
};

MyApp *g_pApp;

wxIMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
	g_pApp = this;
	MyFrame *frame = new MyFrame();
	frame->Show(true);
	return true;
}

MyFrame::MyFrame():
	wxFrame(NULL, wxID_ANY, "test", wxDefaultPosition, wxSize(800, 450))
{
	m_pCont = new wxPanel(this, wxID_ANY);
	m_pRibbon = new cRibbon(m_pCont);
	wxBoxSizer *pMainSizer = new wxBoxSizer(wxVERTICAL);
	pMainSizer->Add(m_pRibbon, 0, wxEXPAND);
	m_pCont->SetSizer(pMainSizer);
	
	Bind(wxEVT_RIBBONBUTTONBAR_CLICKED, onTestBtn, this, idRibbonOnlineConnect);

	this->Center();
}

void MyFrame::onTestBtn(wxRibbonButtonBarEvent &WXUNUSED(evt))
{
	tExampleDlg *pDlg = new tExampleDlg(this);
	pDlg->ShowModal(); // Blocking, returns stuff
	pDlg->Destroy();
}
And here's what gdb shows me.

Code: Select all

GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from D:\prg\wx_test\bin/wxtest.exe...done.
(gdb) run
Starting program: D:\prg\wx_test\bin/wxtest.exe
[New Thread 10332.0x1bec]
[New Thread 10332.0x86c]
[New Thread 10332.0x15d0]
[New Thread 10332.0x1218]

Program received signal SIGSEGV, Segmentation fault.
0x009244f0 in wxCheckDynamicCast(wxObject*, wxClassInfo*) ()
(gdb) bt
#0  0x009244f0 in wxCheckDynamicCast(wxObject*, wxClassInfo*) ()
#1  0x00000000 in ?? ()
Any ideas what I could've done wrong? I'm struggling with it since few days and it's starting to drive me nuts.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Ribbon buttons + dialogs = crashes

Post by catalin »

Bind(wxEVT_RIBBONBUTTONBAR_CLICKED, onTestBtn, this, idRibbonOnlineConnect);
The function name should be passed using its address and the fully qualified name, in your case "&MyFrame::onTestBtn".
User avatar
tehKaiN
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 25, 2017 7:09 pm
Location: Poland
Contact:

Re: Ribbon buttons + dialogs = crashes

Post by tehKaiN »

Thanks for the reply. I'm mostly C-head and started coding in cpp not so long ago. I wasn't aware of existence of pointer to member functions. Unfortunately, this didn't help. So I did:

Code: Select all

Bind(wxEVT_RIBBONBUTTONBAR_CLICKED, &MyFrame::onTestBtn, this, idRibbonOnlineConnect);
and it didn't help :(
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Ribbon buttons + dialogs = crashes

Post by ONEEYEMAN »

Hi,
You still have the same crash? With the same backtrace?

Try:

Code: Select all

m_pRibbon->Bind();
Thank you.

BTW, you did compile the library in Debug mode, right? And you used exactly the same options for compiling the application? And the ribbon sample does work for you?
User avatar
tehKaiN
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 25, 2017 7:09 pm
Location: Poland
Contact:

Re: Ribbon buttons + dialogs = crashes

Post by tehKaiN »

Still same thing, same backtrace.
I've compiled wxwidgets using release. I'll try with debug during weekend if anyone won't help me until then. Ribbon sample worked for me. I've tried modifying it by changing one of ribbon button events to same dialog creation and it works, so I haven't slightest idea what's going on.

Moreover, I've used exactly same bind syntax as in 1st post for other events and everything worked fine. I guess it's not just that triggering this event is main source of crash, but app crashes instantly if one changes code so that dialog is created just after bind:

Code: Select all

	m_pRibbon->Bind(wxEVT_RIBBONBUTTONBAR_CLICKED, &MyFrame::onTestBtn, this, idRibbonOnlineConnect);
	tExampleDlg *pDlg = new tExampleDlg(this);
	pDlg->ShowModal(); 
	pDlg->Destroy();
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Ribbon buttons + dialogs = crashes

Post by ONEEYEMAN »

Hi,
It always a good idea to compile a debug version of everything during development. ;-)
But if the sample works for you - try to find what do you do differently and see if that helps.

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

Re: Ribbon buttons + dialogs = crashes

Post by doublemax »

Code: Select all

Bind(wxEVT_RIBBONBUTTONBAR_CLICKED, &MyFrame::onTestBtn, this, idRibbonOnlineConnect);
I tested your code with that line under Visual Studio and it worked fine. Try a clean rebuild of the wxWidgets libraries and your program. And make sure you're not including headers or libraries from other wxWidgets versions that you may have on your system.
Use the source, Luke!
User avatar
tehKaiN
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 25, 2017 7:09 pm
Location: Poland
Contact:

Re: Ribbon buttons + dialogs = crashes

Post by tehKaiN »

So I've recompiled wx3.0.3 with latest TDM, using following line, without changing anything in setup.h:

Code: Select all

mingw32-make -f makefile.gcc BUILD=debug SHARED=0 CXXFLAGS="-fno-keep-inline-dllexport -std=gnu++11"
aaaand... it works! I've then removed wxwidgets and unzipped it once again and compiled with:

Code: Select all

mingw32-make -f makefile.gcc BUILD=release SHARED=0 CXXFLAGS="-fno-keep-inline-dllexport -std=gnu++11"
And it crashes. So I guess it's some kind of bug :)
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Ribbon buttons + dialogs = crashes

Post by doublemax »

I just tested again with wx3.0.3 (was using latest GIT version before) and TDM-GCC 5.1.0 under Windows 10/x64. Still works in debug and release mode.

I honestly have no idea what could be wrong on your side.
Use the source, Luke!
User avatar
tehKaiN
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 25, 2017 7:09 pm
Location: Poland
Contact:

Re: Ribbon buttons + dialogs = crashes

Post by tehKaiN »

So I've switched to wx3.1.0, built with debug - works.
Then I made clean install and done release shared library - works.
Then another clean install as release static library - broken in same way.

So I guess I'll stick with DLL version, although I preferred having one 12MiB .exe instead of 2MiB .exe and 30MiB of DLLs :)

OS is Win10 x64, TDM is 32-bit.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Ribbon buttons + dialogs = crashes

Post by ONEEYEMAN »

Hi,
That's very weird.
What happen if you do statuc debug build? And if it fails - would be nice to have a backtrace...

Thank you.
User avatar
tehKaiN
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 25, 2017 7:09 pm
Location: Poland
Contact:

Re: Ribbon buttons + dialogs = crashes

Post by tehKaiN »

All debug builds work - statically and dynamic linked too. Only static release cause problems.

I have annual system format pending anyway, so perhaps it's something that will go away after setting up fresh OS. However, I've even uninstalled all my compilers, cleaned up PATH etc. so there shouldn't be any conflicts.
Post Reply