I have a problem with a vector going out of range. What i'm trying to do is loop through a vector that resembles my heightmap and assign a value I get from my perlin-noise map.
void mHeightMap::fillTerrain( LAND_TYPES type )
{
float landMass = 0.0f;
float singleElement = float( 1.0f / ( x_ * y_ ));
if( type == BAY )
{
srand( (int)time(NULL) );
Perlin noiseMap( 6,.39f,1,rand()%16);
for(int i = 0; i < x_; i++)
{
for(int j = 0; j < y_; j++)
{
try
{
float height = noiseMap.Get( float( i/x_ ), float( j/y_ ));
map.at(i + (j * x_)) = height;
if( height >= 0.0f )
{
landMass += singleElement;
}
}
catch ( char* str )
{
printf( str );
}
}
}
if( ( landMass < 0.25f ) || ( landMass > 0.75f ) )
{
map.clear();
fillTerrain( type );
}
}
}
definition and constructor
mHeightMap::mHeightMap()
{
x_ = 256;
y_ = 256;
z_ = 1.0f;
map.resize( x_ * y_ * sizeof(float) );
}
class mHeightMap
{
public:
mHeightMap();
mHeightMap( int x, int y, float z );
~mHeightMap();
int x_;
int y_;
float z_;
void operator+= (mHeightMap);
void operator*= (mHeightMap);
void fillPerlin();
void fillUniform();
void fillVoronoi();
void fillTerrain( LAND_TYPES type );
private:
vector<mTriangle> mesh;
vector<float> map;
};
terminate called after throwing an instance of 'std::out of range'
what(): vector::_M_range_check
using GNU C++ Compiler