Index: /branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
===================================================================
--- /branches/terrain/src/lib/graphics/importer/terrain/terrain.cc	(revision 8769)
+++ /branches/terrain/src/lib/graphics/importer/terrain/terrain.cc	(revision 8770)
@@ -12,4 +12,14 @@
 #endif
 
+bool validateSize( int _s ) {
+	_s-=1;
+	int s = 16;
+	while ( s <= _s ) {
+		if (s == _s )
+			return true;
+		s*=2;
+	}
+	return false;
+}
 void Terrain::build()
 {
@@ -21,5 +31,12 @@
 		return;
 	}		
-	
+	if ( !validateSize( tmpData->h ) || !validateSize( tmpData->w ) ) {
+		PRINTF(0)( "The size of the elevation map must be 2^n+1x2^m+1. and at least 17x17" );
+		return;
+	}
+	if ( tmpData->format->BytesPerPixel != 1 ) {
+		PRINTF(0)( "The elevetation map must be an 8bit image!" );
+		return;
+	}
 	heightfield.height = tmpData->h;
 	heightfield.width = tmpData->w;
@@ -29,5 +46,4 @@
 	memcpy( heightfield.data, tmpData->pixels, sizeof(Uint8)*dataSize );
 	SDL_FreeSurface( tmpData );
-	//TODO: Perform some checks... size, bits and so on
 	pagesX = (heightfield.width/(pageSize-1) );
 	pagesZ = (heightfield.height/(pageSize-1) );
@@ -334,5 +350,5 @@
 		break;
     case 3:
-        if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
+        if( SDL_BYTEORDER == SDL_BIG_ENDIAN )
             pixel = p[0] << 16 | p[1] << 8 | p[2];
         else
@@ -343,5 +359,5 @@
 		break;
     default:
-        return 0;       /* shouldn't happen, but avoids warnings */
+        return 255;       /* shouldn't happen, but avoids warnings */
     }
 	Uint8 r,g,b,a;
Index: /branches/terrain/src/lib/graphics/importer/terrain/terrain.h
===================================================================
--- /branches/terrain/src/lib/graphics/importer/terrain/terrain.h	(revision 8769)
+++ /branches/terrain/src/lib/graphics/importer/terrain/terrain.h	(revision 8770)
@@ -80,4 +80,10 @@
 		{ 
 			pageSize = 17;
+			pagesX = pagesZ = 0;
+			lightmap = NULL;
+			heightmapSource = "";
+			root = NULL;
+			current = 0;
+			activePages = NULL;
 			scale  = Triple( 1.0f, 3.0f, 1.0f );
 			frustum = new Frustum();
@@ -207,4 +213,5 @@
 inline float Terrain::getAltitude( int _x, int _z ) const
 {
+	assert( heightfield.data );
 	if ( _x < 0 || _x >= heightfield.width || _z < 0 || _z >= heightfield.height ) {
 		return 0.0f;
Index: /branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
===================================================================
--- /branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc	(revision 8769)
+++ /branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc	(revision 8770)
@@ -34,10 +34,15 @@
 	errors = new LODError[TerrainPage::MAX_LODS];
 	vertices = NULL; indices = NULL; 
-	position = Triple( scale.x*_xOffset, 0.0f, scale.z*_zOffset );
+	left = top = bottom = right = NULL;
+	for ( int i = 0; i < 8; ++i )
+		layerVisibility[i] = LV_NO;	
+		
+	position = Triple( scale.x*_xOffset, 
+		0.0f, scale.z*_zOffset );
 	isVisible = false;
 	next = NULL;
 	active = false;
-	previous = NULL;
-	currentLOD = -1;
+	previous = NULL; 
+	currentLOD = -1; wantedLOD = -1;
 	hasfull = false;
 	forceTesselation = true;
Index: /branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h
===================================================================
--- /branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h	(revision 8769)
+++ /branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h	(revision 8770)
@@ -83,6 +83,6 @@
 		
 		/**
-		 * @brief Sets the visibility to _flag. If the visibility changed, the vertex and index
-		 * arrays are allocated or freed, respectively.
+		 * @brief Sets the visibility to _flag. If the visibility changed, the vertex and 
+		 * index arrays are allocated or freed, respectively.
 		 */
 		inline void setVisibility( bool _flag );
@@ -109,5 +109,6 @@
 		
 		/**
-		 * @return The curren tween factor. This is a floating point value  between 0.0f and 1.0f
+		 * @return The curren tween factor. This is a floating point value  between 0.0f 
+		 * and 1.0f
 		 */
 		float getTween() { return 0.0f; }
@@ -271,5 +272,4 @@
 		int							currentLOD,
 									wantedLOD;
-		float						tween;
 		pTerrainPage 				left, 
 									right,
Index: /branches/terrain/src/lib/graphics/importer/terrain/types.h
===================================================================
--- /branches/terrain/src/lib/graphics/importer/terrain/types.h	(revision 8769)
+++ /branches/terrain/src/lib/graphics/importer/terrain/types.h	(revision 8770)
@@ -144,4 +144,5 @@
 	int				pitch;
 	UByte			*data;
+	Heightfield() { data = NULL; width=0;height=0;pitch=0;}
 };
 
