[gdal-dev] NewDataset and SetBand error

Seung Ae Lim salim at pixoneer.co.kr
Thu Nov 7 01:03:14 PST 2013


Dear,

I make a console application with VS2010 linking "gdal_i.lib".
The steps are :
1. Create New Dataset and Band in main.cpp
class XXDataset : public GDALPamDataset
{
public:
	XXDataset() {};
	~XXDataset() {};

	static GDALDataset* Open(GDALOpenInfo*);
};

class XXRasterBand : public GDALPamRasterBand
{
public:
	XXRasterBand( GDALDataset*, int, GDALDataType );
	~XXRasterBand() {};
};



GDALDataset* XXDataset::Open(GDALOpenInfo* pOpenInfo)
{
	XXDataset* poDS = new XXDataset();
	poDS- >nRasterXSize = 100;
	poDS- >nRasterYSize = 200;
	poDS- >eAccess = GA_Update;
	poDS- >nBands = 3;

	int iBand = 0;
	for(iBand = 1; iBand < = 3; iBand++ )
	{
		XXRasterBand* band = new XXRasterBand( poDS, iBand, GDT_Byte);
		poDS- >SetBand( iBand, band );
	}

	return poDS;
}

XXRasterBand::XXRasterBand( GDALDataset *poDS, int nBand, GDALDataType eType)
{
	this- >poDS = poDS;
	this- >nBand = nBand;
	this- >eDataType = eType;
	nRasterXSize = 100;
	nRasterYSize = 200;
	nBlockXSize = nRasterXSize;
	nBlockYSize = nRasterYSize;
}

2. Add the code in main function
void main()
{


    GDALDataset* pDSTemp = XXDataset::Open(NULL);
	if (pDSTemp) GDALClose(pDSTemp);
}



I compile and try to debug this app.
But in "poDS->SetBand" line of "XXDataset::Open", the app is broken when the first band is ready to set.
In XXDataset::Open, all value of parameters is right.
But When stepping into the "SetBand" function, the values may be corrupted.
"papobands" of GDALDataset is not null and it make an error.

Please let me know the reason or some tips.

Thanks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20131107/84733a3e/attachment-0001.html>


More information about the gdal-dev mailing list