[Kstars-devel] KDE/kdeedu/kstars/kstars

David Faure faure at kde.org
Thu Dec 6 22:55:20 CET 2007


On Thursday 06 December 2007, Dirk Mueller wrote:
> On Thursday 06 December 2007, Jason Harris wrote:
> 
> > indicated the last code executed was ~JupiterMoons(), which consisted
> > of a single line:
> >
> >     delete[] Moon;
> >
> > because the four moons were stored as an array of TrailObject
> > pointers.  After a long time spent trying various fixes (I was misled
> > into thinking the problem was related to KPlotWidget, because there's
> > a similar-seeming and still-unresolved crash in modvizequinox, and
> > both use a KPlotWidget), I decided to change from an array of
> > TrailObject pointers to a QList.  Now the dtor looks like:
> >
> >     qDeleteAll( Moon );
> >
> > voila', no more crash.
> 
> Thats because the previous code was plain wrong. delete [] Moon doesn't delete 
> the members of the array, it deletes the array itself. with other words, 
> you're deleting a part of your class, which causes the crash you see. 
> 
> The correct fix would have been
> 
> for (int i = 0; i < magicsize; ++i)
>   delete Moon[i];
> 
> 
> Of course using QList instead of an array is making access slower. Not sure if 
> thats a problem. 
 
Use QVector instead and the access will be exactly like when using a C array.

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).


More information about the Kstars-devel mailing list