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

Dirk Mueller mueller at kde.org
Thu Dec 6 22:08:36 CET 2007


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. 


Dirk


More information about the Kstars-devel mailing list