IRasterBand.ComputeStatsAndHist() .. Attempted to read or write protected memory

341
3
11-19-2013 03:36 AM
martinmaretta
Occasional Contributor
Hi I have one very strange error when i try compute statistics for my Raster (only happens whit FGDB Raster). It happens when i overwrite raster (when i create new raster everything is OK). Any Ideas? thanks

            Dim pRasterCol As IRasterBandCollection
            pRasterCol = pRaster
            Dim pBand As IRasterBand
            pBand = pRasterCol.Item(0)
            pBand.ComputeStatsAndHist() 'ERROR

ERROR = "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

I create raster like this>

Dim copyRaster As ESRI.ArcGIS.DataManagementTools.CopyRaster = New ESRI.ArcGIS.DataManagementTools.CopyRaster()
            Dim gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor
            gp.OverwriteOutput = True
            gp.AddOutputsToMap = False

            copyRaster.in_raster = pRaster
            copyRaster.out_rasterdataset = pOutputPath
            copyRaster.nodata_value = -9999
            copyRaster.pixel_type = "32_BIT_FLOAT"

            gp.Execute(copyRaster, Nothing)
            gp = Nothing
            copyRaster = Nothing
0 Kudos
3 Replies
ParitoshGupta
New Contributor III
Hi Martin
    This common error is related to the object memory not being released. The pRaster object memory should be released before attempting to compute statistics using it. You can use System.Runtime.InteropServices.Marshal.ReleaseCOMObject method to do it.
0 Kudos
martinmaretta
Occasional Contributor
Thanks a lot
0 Kudos
ParitoshGupta
New Contributor III
Hi Martin
   Request you to vote my reply up by clicking on ^ key.

Regards
0 Kudos