[gdal-dev] Crash during ChunkAndWarpImage in C++ API

Craig Delancy cdelancy at blackfangtechnologies.com
Fri Aug 13 07:16:28 PDT 2021


When calling ChunkAndWarpImage I have an unhandled exception on the line
pTransformArg = psInfo->pDstTransformArg;
in gdaltransformer.cpp.

Does anyone have any advice for where I should start debugging or what I may be doing wrong?
My full function is as follows:

bool WarpDataset(GDALDataset* srcDataset, GDALDataset*& dstDataset, int32 px, int32 py,
                FVector2D TopLeft, FVector2D BottomRight, OGRSpatialReference* dstSpatRef)
{
                if (!srcDataset)
                {
                                return false;
                }

                GDALAllRegister();

                //Source data
                GDALDatasetH hSrcDS = GDALDataset::ToHandle(srcDataset);
                CSLConstList CSL = CSLConstList();
                GDALDriverH hDriver = GDALGetDriverByName("MEM");

                if (!hDriver)
                {
                                UE_LOG(LogTemp, Warning, TEXT("Resize failed. No valid driver!"));
                                return false;
                }

                int32 NumBands = srcDataset->GetRasterCount();
                if (NumBands < 1)
                {
                                return false;
                }

                GDALDataType sourceDatatype = GDALGetRasterDataType(GDALGetRasterBand(hSrcDS, 1));
                //Destination data
                GDALDatasetH hDstDS = GDALCreate(hDriver, "", px, py, NumBands, sourceDatatype, CSL);

                if (dstSpatRef)
                {
                                char* pszDstWKT = NULL;
                                int32 Err = dstSpatRef->exportToWkt(&pszDstWKT);
                                GDALDataset::FromHandle(hDstDS)->SetProjection(pszDstWKT);
                }
                else
                {
                                char* pszDstWKT = NULL;
                                int32 Err = GDALDataset::FromHandle(hSrcDS)->GetSpatialRef()->exportToWkt(&pszDstWKT);
                                GDALDataset::FromHandle(hDstDS)->SetProjection(pszDstWKT);
                }

                GDALDataset::FromHandle(hDstDS)->SetMetadata(GDALDataset::FromHandle(hSrcDS)->GetMetadata());

                bool InvertY = true;

                //Affine
                double T[6];
                double MaxX = BottomRight.X;
                double MaxY = BottomRight.Y;
                double MinX = TopLeft.X;
                double MinY = TopLeft.Y;

                T[0] = (MaxX - MinX) / double(px);
                T[1] = 0;
                T[2] = MinX;
                T[3] = (InvertY ? (MinY - MaxY) : (MaxY - MinY)) / double(py);
                T[4] = 0;
                T[5] = InvertY ? MaxY : MinY;

                GDALDataset::FromHandle(hDstDS)->SetGeoTransform(T);


                // Setup warp options.

                GDALWarpOptions* psWarpOptions = GDALCreateWarpOptions();

                psWarpOptions->hSrcDS = hSrcDS;
                psWarpOptions->hDstDS = hDstDS;

                psWarpOptions->nBandCount = NumBands;
                psWarpOptions->panSrcBands = (int*)CPLMalloc(sizeof(int) * psWarpOptions->nBandCount);
                psWarpOptions->panDstBands = (int*)CPLMalloc(sizeof(int) * psWarpOptions->nBandCount);

                for (int32 B = 0; B < NumBands; B++)
                {
                                psWarpOptions->panSrcBands[B] = B + 1;
                                psWarpOptions->panDstBands[B] = B + 1;
                }

                psWarpOptions->pfnProgress = GDALTermProgress;

                // Establish reprojection transformer.
                psWarpOptions->pTransformerArg = GDALCreateGenImgProjTransformer(hSrcDS, GDALGetProjectionRef(hSrcDS),
                                hDstDS, GDALGetProjectionRef(hDstDS), FALSE, 0.0, 1);
                psWarpOptions->pfnTransformer = GDALGenImgProjTransform;

                // Initialize and execute the warp operation.

                GDALWarpOperation oOperation;

                oOperation.Initialize(psWarpOptions);
                oOperation.ChunkAndWarpImage(0, 0, GDALGetRasterXSize(hDstDS), GDALGetRasterYSize(hDstDS));

                GDALDestroyGenImgProjTransformer(psWarpOptions->pTransformerArg);
                GDALDestroyWarpOptions(psWarpOptions);

                dstDataset = GDALDataset::FromHandle(hDstDS);

                for (int32 B = 0; B < dstDataset->GetRasterCount(); B++)
                {
                                double Mean, Min, Max, SDev;
                                dstDataset->GetRasterBand(B + 1)->ComputeStatistics(0, &Min, &Max, &Mean, &SDev, NULL, NULL);
                }

                return true;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210813/b9be9505/attachment-0001.html>


More information about the gdal-dev mailing list