PDA

View Full Version : Heap corruption in QwtPolarGrid::updateScaleDiv



kreyszig
15th August 2017, 16:16
This post is aimed at Uwe, I hope this may sound familiar or flag up something I have set up incorrectly:

I have an issue (Invalid address specified to RtlFreeHeap) that only seems to show up in release builds (on windows). I am seeing very repeatable heap corruption whenever I enable more than a single axis in my subclass of QwtPolarPlot.

edit: in fact this is an issue whenever I use even a single axis which is not AxisAzimuth

e.g. here is my constructor for my subclass. As you can see below it is a slightly modified version of one of the polardemo example, removing some of the setup. I have my own member interval classes instead of having them declared outside the class as in the example, but otherwise it is pretty similar.

The last readable code I have in my stack trace is axis.scaleDraw->setScaleDiv( sd ); in qwt_polar_grid.cpp.

Does this ring a bell at all regarding double frees or mismatch between delete and free, for example? Obviously I am not adding curves until after I initialise the plot, unlike the example this was taken from, but if I turn on the axes after adding the curve I still have the same problem.

Any thoughts would be very well received - this gets through Dr Memory (-light) OK on debug and release. I am using qwtpolar 1.1.1, qt 4.7.1 and Qwt 6.1.0. Qt and Qwt are both shared libraries; I have tried qwtpolar as both shared and static library and get the same error.




class PolarPlot: public QwtPolarPlot
{
Q_OBJECT

public:
PolarPlot( QString name, QWidget * = NULL );
void add_curve(QString name, PolarCurve * curve);
//void update_curve(QString name, double * r, double *t);
virtual void replot();
private:

QwtPolarGrid *d_grid;
QwtInterval _radialInterval;
QwtInterval _azimuthInterval;

};

PolarPlot::PolarPlot( QString name, QWidget *parent ):
QwtPolarPlot( QwtText( name ), parent )
{
setAutoReplot( false );

setPlotBackground( QColor("#ffffb3"));

_radialInterval.setMinValue(0);
_radialInterval.setMaxValue(360.0);
_azimuthInterval.setMinValue(0);
_azimuthInterval.setMaxValue(360.0);

setScale( QwtPolar::ScaleRadius,
_azimuthInterval.minValue(), _azimuthInterval.maxValue(),
_azimuthInterval.width());

setScaleMaxMinor( QwtPolar::Azimuth, 2 );
setScale( QwtPolar::ScaleRadius,
_radialInterval.minValue(), _radialInterval.maxValue() );

// grids, axes

d_grid = new QwtPolarGrid();
d_grid->setPen( QPen(Qt::darkGray) );
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
{
d_grid->showGrid( scaleId );
d_grid->showMinorGrid( scaleId );

QPen minorPen( Qt::gray );
d_grid->setMinorGridPen( scaleId, minorPen );
}
d_grid->setAxisPen( QwtPolar::AxisAzimuth, QPen( Qt::black ) );
d_grid->setAxisPen( QwtPolar::AxisTop, QPen( Qt::red ) );
d_grid->setAxisPen( QwtPolar::AxisRight, QPen( Qt::black ) );
d_grid->setAxisPen( QwtPolar::AxisLeft, QPen( Qt::black ) );
d_grid->setAxisPen( QwtPolar::AxisBottom, QPen( Qt::black ) );


d_grid->showAxis( QwtPolar::AxisAzimuth, true);
d_grid->showAxis( QwtPolar::AxisTop, true); // <-unless this and all non azimuth axes are false, I get heap corruption
d_grid->showAxis( QwtPolar::AxisRight, false);
d_grid->showAxis( QwtPolar::AxisLeft, false );
d_grid->showAxis( QwtPolar::AxisBottom, false );

d_grid->showGrid( QwtPolar::Azimuth, true);
d_grid->showGrid( QwtPolar::Radius, true );
d_grid->attach( this );

// curves

/*for ( int curveId = 0; curveId < PlotSettings::NumCurves; curveId++ )
{
d_curve[curveId] = createCurve( curveId );
d_curve[curveId]->attach( this );
}*/

// markers
/*QwtPolarMarker *marker = new QwtPolarMarker();
marker->setPosition( QwtPointPolar( 57.3, 4.72 ) );
marker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse,
QBrush( Qt::white ), QPen( Qt::green ), QSize( 9, 9 ) ) );
marker->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop );

QwtText text( "Marker" );
text.setColor( Qt::black );
QColor bg( Qt::white );
bg.setAlpha( 200 );
text.setBackgroundBrush( QBrush( bg ) );

marker->setLabel( text );
marker->attach( this );

QwtLegend *legend = new QwtLegend;
insertLegend( legend, QwtPolarPlot::BottomLegend );*/
}

Added after 42 minutes:

In addition, I also see the same problem if I build the polardemo example myself in visual studio. I am doing this by hand, i.e. adding the source and headers to a new project and setting up as per my other qt projects. I have checked with a dependency walker that the dlls I am using are consistent with what I expect, i.e. the dlls built on this machine from source.

kreyszig
16th August 2017, 09:47
Nevermind. I had rebuilt qwt while trying to sort this out and hadn't moved the new qwt.dll into my path. With this in place it is fine.