[gdal-dev] [gdal 3.12beta] Normal chain of explicit destruction does not work with ComputedDataset
Momtchil Momtchev
momtchil at momtchev.com
Fri Oct 24 03:40:02 PDT 2025
I have modified one of the algebra examples as follows:
#include<gdal_priv.h>
intmain() {
GDALAllRegister();
autopoDS=std::unique_ptr<GDALDataset>(GDALDataset::Open("test/data/a39se10.jpg"));
auto&R=*(poDS->GetRasterBand(1));
auto&G=*(poDS->GetRasterBand(2));
auto&B=*(poDS->GetRasterBand(3));
GDALRasterBand*graylevel=newGDALComputedRasterBand((0.299*R+0.587*G+0.114*B).AsType(GDT_Byte));
autopoGTiffDrv=GetGDALDriverManager()->GetDriverByName("GTiff");
std::unique_ptr<GDALDataset>(
poGTiffDrv->CreateCopy("graylevel.tif", graylevel->GetDataset(), false,
nullptr, nullptr, nullptr))
.reset();
GDALDataset*dh=graylevel->GetDataset();
deletegraylevel;
dh->Close();
return0;
}
I allocate graylevel on the heap, I obtain a pointer to the
GDALComputedDataset and I attempt to destroy first the
GDALComputedRasterBand then the GDALComputedDataset. This fails with a
crash in Close. Is this a bug or am I not supposed to do this? I am
doing it, because this is the usual chain of destruction events for
objects returned to JS. RasterBands hold a reference to their Dataset in
order to prevent the object from being GCed.
--
Momtchil Momtchev<momtchil at momtchev.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20251024/28f4f62b/attachment.htm>
More information about the gdal-dev
mailing list