Stack overflow in Resampler2D
-----------------------------

                 Key: GEOT-3585
                 URL: http://jira.codehaus.org/browse/GEOT-3585
             Project: GeoTools
          Issue Type: Bug
          Components: core coverage
    Affects Versions: 2.7.1
            Reporter: Joshua Portway


I'm getting a stack overflow exception when resampling a GridCoverage2D

Here's the stack trace :

{noformat}
Caused by: java.lang.StackOverflowError
        at java.lang.ThreadLocal$ThreadLocalMap.getEntry(ThreadLocal.java:362)
        at java.lang.ThreadLocal$ThreadLocalMap.access$000(ThreadLocal.java:242)
        at java.lang.ThreadLocal.get(ThreadLocal.java:127)
        at 
org.geotools.factory.RecursionCheckingHelper.addAndCheck(RecursionCheckingHelper.java:11)
        at 
org.geotools.factory.FactoryRegistry.usesAcceptableHints(FactoryRegistry.java:545)
        at 
org.geotools.factory.FactoryRegistry.usesAcceptableHints(FactoryRegistry.java:617)
        at 
org.geotools.factory.FactoryRegistry.usesAcceptableHints(FactoryRegistry.java:617)
        at 
org.geotools.factory.FactoryRegistry.isAcceptable(FactoryRegistry.java:504)
        at 
org.geotools.factory.FactoryRegistry.getServiceImplementation(FactoryRegistry.java:435)
        at 
org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:363)
        at 
org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:143)
        at 
org.geotools.referencing.ReferencingFactoryFinder.getFactory(ReferencingFactoryFinder.java:193)
        at 
org.geotools.referencing.ReferencingFactoryFinder.getCoordinateOperationFactory(ReferencingFactoryFinder.java:318)
        at 
org.geotools.coverage.processing.operation.Resampler2D.reproject(Resampler2D.java:410)
        at 
org.geotools.coverage.processing.operation.Resampler2D.reproject(Resampler2D.java:692)
        at 
org.geotools.coverage.processing.operation.Resampler2D.reproject(Resampler2D.java:692)
etc...
{noformat}

And this is my code that's calling it :

{code:title=Resample Stack Overflow|borderStyle=solid}
GridCoverage2D alphaCoverage = buildAlphaCoverage(newCoverage, bandNumber);
// isolate the band we're interested in so we don't bother resampling the 
entire gridCoverage

// GridCoverage2D singleBand = (GridCoverage2D) 
Operations.DEFAULT.selectSampleDimension(newCoverage, new int[]{bandNumber});

// this about about here is because the simple selectSampleDimension commented 
method above doesn't work when using the pure java JAI implementation on mac. 
urgh.
WritableRaster wr = newCoverage.getRenderedImage().copyData(null);
float[] samples = wr.getSamples(0, 0, wr.getWidth(), wr.getHeight(), 
bandNumber, (float[]) null);
DataBuffer buffer = new DataBufferFloat(samples, samples.length);
SampleModel sm = new BandedSampleModel(DataBuffer.TYPE_FLOAT, wr.getWidth(), 
wr.getHeight(), 1);
WritableRaster singleBandRaster = WritableRaster.createWritableRaster(sm, 
buffer, null);
final GridCoverageFactory fac = 
CoverageFactoryFinder.getGridCoverageFactory(null);
GridCoverage2D singleBand = fac.create("single band", singleBandRaster, 
newCoverage.getEnvelope());

// resample the incoming data to the resolution of the cached accumulator 
coverage
MathTransform2D gridToCRS = accumulator.getGridGeometry().getGridToCRS2D();
GridGeometry2D gg = new GridGeometry2D(PixelInCell.CELL_CENTER, gridToCRS, 
envelope, null);
GridCoverage2D resampledData = (GridCoverage2D) 
Operations.DEFAULT.resample(singleBand, 
accumulator.getCoordinateReferenceSystem(), gg, 
Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
GridCoverage2D resampledAlpha = (GridCoverage2D) 
Operations.DEFAULT.resample(alphaCoverage, 
accumulator.getCoordinateReferenceSystem(), gg, 
Interpolation.getInstance(Interpolation.INTERP_BICUBIC));


{code} 


the problem seems to be a recursion in a bug workaround in Resampler2D :

{code:title=Problem Recursion}
if (!(new GeneralEnvelope(source).contains(target, true))) {
    if (interpolation != null && !(interpolation instanceof 
InterpolationNearest)) {
        return reproject(sourceCoverage, targetCRS, targetGG, null, hints, 
background);
    } else {
        // If we were already using nearest-neighbor interpolation, force
        // usage of WarpAdapter2D instead of WarpAffine. The price will be
        // a slower reprojection.
        forceAdapter = true;
    }
}
{code}




-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to