Skip to content

Commit

Permalink
keep row col in limits to avoid crash with 32661; decrease max cp mat…
Browse files Browse the repository at this point in the history
…rix size

git-svn-id: http://svn.osgeo.org/qgis/trunk@15845 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Apr 28, 2011
1 parent e1c2bbc commit 84ba7c7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/core/qgsrasterprojector.cpp
Expand Up @@ -85,7 +85,7 @@ QgsRasterProjector::QgsRasterProjector(
}
// What is the maximum reasonable size of transformatio matrix?
// TODO: consider better when to break - ratio
if ( mCPRows * mCPCols > 0.25 * mDestRows * mDestCols )
if ( mCPRows * mCPCols > 0.0625 * mDestRows * mDestCols )
{
QgsDebugMsg( "Too large CP matrix" );
mApproximate = false;
Expand Down Expand Up @@ -312,6 +312,14 @@ void QgsRasterProjector::preciseSrcRowCol( int theDestRow, int theDestCol, int *
*theSrcRow = ( int ) floor(( mSrcExtent.yMaximum() - y ) / mSrcXRes );
*theSrcCol = ( int ) floor(( x - mSrcExtent.xMinimum() ) / mSrcYRes );

// With epsg 32661 (Polar Stereographic) it was happening that *theSrcCol == mSrcCols
// For now silently correct limits to avoid crashes
// TODO: review
if ( *theSrcRow >= mSrcRows ) *theSrcRow = mSrcRows - 1;
if ( *theSrcRow < 0 ) *theSrcRow = 0;
if ( *theSrcCol >= mSrcCols ) *theSrcCol = mSrcCols - 1;
if ( *theSrcCol < 0 ) *theSrcCol = 0;

assert( *theSrcRow < mSrcRows );
assert( *theSrcCol < mSrcCols );
}
Expand Down Expand Up @@ -357,6 +365,12 @@ void QgsRasterProjector::approximateSrcRowCol( int theDestRow, int theDestCol, i
*theSrcRow = ( int ) floor(( mSrcExtent.yMaximum() - mySrcY ) / mSrcXRes );
*theSrcCol = ( int ) floor(( mySrcX - mSrcExtent.xMinimum() ) / mSrcYRes );

// For now silently correct limits to avoid crashes
// TODO: review
if ( *theSrcRow >= mSrcRows ) *theSrcRow = mSrcRows - 1;
if ( *theSrcRow < 0 ) *theSrcRow = 0;
if ( *theSrcCol >= mSrcCols ) *theSrcCol = mSrcCols - 1;
if ( *theSrcCol < 0 ) *theSrcCol = 0;
assert( *theSrcRow < mSrcRows );
assert( *theSrcCol < mSrcCols );
}
Expand Down

0 comments on commit 84ba7c7

Please sign in to comment.