--- grass57dataset.cpp.orig 2006-11-09 16:05:39.000000000 +0100 +++ grass57dataset.cpp 2006-11-09 16:54:19.000000000 +0100 @@ -1,5 +1,5 @@ /****************************************************************************** - * $Id: grass57dataset.cpp,v 1.6 2006/02/13 17:39:31 rblazek Exp $ + * $Id: grass57dataset.cpp,v 1.7 2006/11/09 15:30:45 rblazek Exp $ * * Project: GRASS Driver * Purpose: Implement GRASS raster read/write support @@ -31,6 +31,9 @@ ****************************************************************************** * * $Log: grass57dataset.cpp,v $ + * Revision 1.7 2006/11/09 15:30:45 rblazek + * check if ResetReading failed + * * Revision 1.6 2006/02/13 17:39:31 rblazek * header files moved to grass * @@ -73,7 +76,7 @@ #define GRASS_MAX_COLORS 100000 // what is the right value -CPL_CVSID("$Id: grass57dataset.cpp,v 1.6 2006/02/13 17:39:31 rblazek Exp $"); +CPL_CVSID("$Id: grass57dataset.cpp,v 1.7 2006/11/09 15:30:45 rblazek Exp $"); CPL_C_START void GDALRegister_GRASS(void); @@ -409,7 +412,10 @@ sNewWindow->ew_res != sOpenWindow.ew_res || sNewWindow->ns_res != sOpenWindow.ns_res || sNewWindow->rows != sOpenWindow.rows || sNewWindow->cols != sOpenWindow.cols ) { - G_close_cell( hCell ); + if( hCell >= 0 ) { + G_close_cell( hCell ); + hCell = -1; + } /* Set window */ G_set_window( sNewWindow ); @@ -423,6 +429,7 @@ if ( (hCell = G_open_cell_old( pszCellName, pszMapset)) < 0 ) { CPLError( CE_Warning, CPLE_AppDefined, "GRASS: Cannot open raster '%s'", pszCellName ); + this->valid = false; return CE_Failure; } @@ -459,6 +466,8 @@ CPLErr GRASSRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage ) { + if ( ! this->valid ) return CE_Failure; + // Reset window because IRasterIO could be previosly called if ( ResetReading ( &(((GRASSDataset *)poDS)->sCellInfo) ) != CE_None ) { return CE_Failure; @@ -510,6 +519,8 @@ /* Calculate the region */ struct Cell_head sWindow; struct Cell_head *psDsWindow; + + if ( ! this->valid ) return CE_Failure; psDsWindow = &(((GRASSDataset *)poDS)->sCellInfo); @@ -526,7 +537,10 @@ /* Reset resolution */ G_adjust_Cell_head ( &sWindow, 1, 1); - ResetReading ( &sWindow ); + if ( ResetReading ( &sWindow ) != CE_None ) + { + return CE_Failure; + } /* Read Data */ CELL *cbuf = NULL;