axeljaeger
09-11-2003, 18:29
Ich hab ein Problem mit der dynamischen Speicherverwaltung. Ich habe eine Methode, die öfters aufgerufen wird. In dieser Methode wird einiges an Speicher bestellt. Der sollte meiner Meinung nach auch wieder freigeben werden und ich glaube, die Praxis gibt mir Recht, jedenfalls stürzt das Programm ab, wenn die Methode dreimal gelaufen ist und kein Speicher freigeben wurde. Wenn ich aber jetzt den Speicher freigebe, stürzt mein Programm sofort ab, nachdem ich das erste mal delete gesagt hab:
void MaskTool::handleMouseRelease(Document* doc, const QPoint & pos)
{
ArtVpath* br = art_new(ArtVpath, 5);
(...)
double matrix[6];
art_affine_scale (&matrix[0],1.0,doc->height() / (double)doc->width());
ArtVpath* circle = art_vpath_new_circle(doc->width() / 2.0, doc->width() / 2.0, doc->width() / 2.0);
ArtVpath* squeezedcircle = art_vpath_affine_transform(circle,matrix);
ArtSVP* circlesvp = art_svp_from_vpath(squeezedcircle);
ArtSVP* rectsvp = art_svp_from_vpath(br);
ArtSVP* finalsvp = art_svp_intersect(rectsvp, circlesvp);
QImage mask = Crimson::instance()->currentDoc()->mask();
mask.create(doc->width(), doc->height(), 8,256);
mask.fill(0);
art_gray_svp_aa (finalsvp,0,0,doc->width(), doc->height(), mask.bits(), doc->width());
for(int i = 0; i < 256; i++)
mask.setColor(i, qRgb(i,i,i));
delete [] br; // Natürlich war immer nur eins von den dreien hier drinn,
art_free(br); //das Programm stürzt immer hier ab, egal welche Variante
delete br;
}
art_new ist wie folgt definiert:
#define art_new(type, n) ((type *)art_alloc ((n) * sizeof(type)))
und art_alloc:
#define art_alloc malloc
Die ganzen Funktionen von libart liefern immer einen anscheinend neu angelegten Pointer auf einen neuen ArtVpath bzw. ArtSVP zurück.
Edit: Interessanterweise wird im Tutorial der Dokumentation zu libArt der Speicher auch nicht freigegeben. Ob das was damit zu tun hat, das da Gnome mit drin ist?
http://www.gnome.org/~mathieu/libart/libart.html
und das Tutorial:
http://www.gnome.org/~mathieu/libart/sample.html#SAMPLE-NON-DISPLAY
void MaskTool::handleMouseRelease(Document* doc, const QPoint & pos)
{
ArtVpath* br = art_new(ArtVpath, 5);
(...)
double matrix[6];
art_affine_scale (&matrix[0],1.0,doc->height() / (double)doc->width());
ArtVpath* circle = art_vpath_new_circle(doc->width() / 2.0, doc->width() / 2.0, doc->width() / 2.0);
ArtVpath* squeezedcircle = art_vpath_affine_transform(circle,matrix);
ArtSVP* circlesvp = art_svp_from_vpath(squeezedcircle);
ArtSVP* rectsvp = art_svp_from_vpath(br);
ArtSVP* finalsvp = art_svp_intersect(rectsvp, circlesvp);
QImage mask = Crimson::instance()->currentDoc()->mask();
mask.create(doc->width(), doc->height(), 8,256);
mask.fill(0);
art_gray_svp_aa (finalsvp,0,0,doc->width(), doc->height(), mask.bits(), doc->width());
for(int i = 0; i < 256; i++)
mask.setColor(i, qRgb(i,i,i));
delete [] br; // Natürlich war immer nur eins von den dreien hier drinn,
art_free(br); //das Programm stürzt immer hier ab, egal welche Variante
delete br;
}
art_new ist wie folgt definiert:
#define art_new(type, n) ((type *)art_alloc ((n) * sizeof(type)))
und art_alloc:
#define art_alloc malloc
Die ganzen Funktionen von libart liefern immer einen anscheinend neu angelegten Pointer auf einen neuen ArtVpath bzw. ArtSVP zurück.
Edit: Interessanterweise wird im Tutorial der Dokumentation zu libArt der Speicher auch nicht freigegeben. Ob das was damit zu tun hat, das da Gnome mit drin ist?
http://www.gnome.org/~mathieu/libart/libart.html
und das Tutorial:
http://www.gnome.org/~mathieu/libart/sample.html#SAMPLE-NON-DISPLAY