Page 1 of 1

wxFreeChart crashes with gcc optimization -O3 and when deriving from wxChartPanel

Posted: Wed Sep 16, 2015 10:44 am
by ErwinH
I'm trying to use wxFreeChart 1.6 with wxWidgets 3.0.2 compiled with gcc under Windows.
There are two scenarios where no chart can be displayed and the demo app and/or the application using wxFreeChart crashes:

- Using gcc compiler optimization -O3 (demo app and user app)
- When deriving from wxChartPanel and creating an instance thereof (only user app)

When I use compiler optimization -O2, there is no crash. When I use the class wxChartPanel directly, there is no crash either.

Does anyone has found a similar behavior and/or has found where the problem is?

Re: wxFreeChart crashes with gcc optimization -O3 and when deriving from wxChartPanel

Posted: Wed Sep 16, 2015 11:22 am
by doublemax
Which gcc version?
- Using gcc compiler optimization -O3 (demo app and user app)
Sounds like a compiler bug.
- When deriving from wxChartPanel and creating an instance thereof (only user app)
Hard to tell without seeing code.

Re: wxFreeChart crashes with gcc optimization -O3 and when deriving from wxChartPanel

Posted: Wed Sep 16, 2015 6:29 pm
by iwbnwif
Please check to make sure that your wxChartPanel is not being set to either wxSize(0,0) or wxDefaultSize (I can't remember which) because this was causing a lot of crashes for me.

Re: wxFreeChart crashes with gcc optimization -O3 and when deriving from wxChartPanel

Posted: Thu Sep 17, 2015 9:07 am
by ErwinH
I use mingw32 with gcc 4.7.2 compiler.

Regarding the second problem, I have found the problem. This is the test class that is derived from wxChartPanel:

Code: Select all

class MyChartPanel : public wxChartPanel
{
public:
	/**
	 * @brief Constructor.
	 *
	 * @param pParent Parent window.
	 * @param pId Window identifier. If <code>wxID_ANY</code> a new unique identifier is created.
	 * @param pPos Window position.
	 * @param pSize Window size.
	 */
	MyChartPanel( wxWindow *pParent, wxWindowID pId = wxID_ANY,
				  const wxPoint &pPos = wxDefaultPosition,
				  const wxSize &pSize = wxDefaultSize );
	/**
	 * @brief Destructor.
	 */
	virtual ~MyChartPanel();
};

// Implementation of constructor & destructor
MyChartPanel::MyChartPanel(	wxWindow *pParent, wxWindowID pId,
							const wxPoint &pPos,
							const wxSize &pSize )
//	: wxChartPanel(this, pId, NULL, pPos, pSize) {			// crash
	: wxChartPanel(pParent, pId, NULL, pPos, pSize) {		// no crash
	// nothing to do here
}

MyChartPanel::~MyChartPanel() {
	// nothing to do here
}
The problem was that I did not pass the parent window to wxChartPanel properly. So now I can derive from wxChartPanel with ease. :D
I did not see a problem with wxSize(0,0) or wxDefaultSize so far.

Re: wxFreeChart crashes with gcc optimization -O3 and when deriving from wxChartPanel

Posted: Thu Sep 17, 2015 9:17 am
by PB
ErwinH wrote:I did not see a problem with wxSize(0,0) or wxDefaultSize so far.
I noticed a similar issue with wxFreeChart and wxWidgets trunk, but it was "only" an assert for me, easily fixed:
https://github.com/pbfordev/wxFreeChart ... 872d6ffb4e

Re: wxFreeChart crashes with gcc optimization -O3 and when deriving from wxChartPanel

Posted: Thu Sep 17, 2015 7:43 pm
by iwbnwif
I noticed a similar issue with wxFreeChart and wxWidgets trunk, but it was "only" an assert for me, easily fixed:
https://github.com/pbfordev/wxFreeChart ... 872d6ffb4e
Ah yes, that is exactly it. Sorry, I forgot that they were only asserts.