code should be:
Code: Select all
virtual ~array2d()
{
if(w && h)
{
for(int i=0; i<w; i++) delete [] data[i];// [] was missing
delete [] data;
}
}
Thanks.
Code: Select all
virtual ~array2d()
{
if(w && h)
{
for(int i=0; i<w; i++) delete [] data[i];// [] was missing
delete [] data;
}
}
Because I can't. array2d is 2 dimensional array while irrlicht list and array are linear.why don't you use the irrList class or irrArray class for that?
Well, I am out of ideas here. I did run whole demo through my compiler but I do not have crash on program exit so I cant track it. If you will be able to dig it up I'll be thankful.The problem is not resolved!
Code: Select all
virtual ~array2d()
{
if(w && h)
{
for(int i=0; i<w; i++)
{
for(int i=0; i<h; i++) delete data[i];
delete [] data;
}
delete [] data;
}
}
Code: Select all
virtual ~array2d()
{
if(w && h)
{
for( int i=0; i<w; i++)
{
delete [] data[i];
}
delete [] data;
}
}
Code: Select all
array2d(s32 width, s32 height) : w(width), h(height)
{
data = new T*[w];
for(int i=0; i<w; i++) data[i] = new T[h];
}
Code: Select all
virtual ~array2d()
{
if(w && h)
{
for(int i=0; i<w; i++) delete data[i]; // change this to delete [] data[i]; and it works
delete [] data;
}
}
Code: Select all
virtual ~array2d()
{
if(w && h)
{
for(int i=0; i<w; i++)
{
for(int i=0; i<h; i++) delete data[i];
delete [] data;
}
delete [] data;
}
}
Code: Select all
// smooth the terrain
// the treshold is the avoid a flat terrain if the 'pass' param is too big
// the pass parameter control how many the algorithm smooth the terrain
// the first function smooth the whole terrain, whereas the second smooth only
// the specified part of terrain
virtual void smoothVertex(f32 treshold, s32 pass = 1);
virtual void smoothVertex(s32 w, s32 h, s32 ww, s32 hh, f32 treshold, s32 pass = 1);
Code: Select all
// smooth the terrain
void ShTlTerrainSceneNode::smoothVertex(f32 treshold, s32 pass)
{
for(int currentPass = 1; currentPass <= pass; currentPass++)
{
for(int y = 0; y <= Size.Height; y++){
for(int x = 0; x <= Size.Width; x++){
if(x > 0 && x < Size.Width){
if(fabs(getHeight(x, y) - (getHeight(x-1, y) + getHeight(x+1, y) + 2*getHeight(x, y))/4.0) >= treshold)
setHeight(x, y, (getHeight(x-1, y) + getHeight(x+1, y) + 2*getHeight(x, y))/4.0);
}
if(y > 0 && y < Size.Width){
if(fabs(getHeight(x, y) - (getHeight(x, y-1) + getHeight(x, y+1) + 2*getHeight(x, y))/4.0) >= treshold)
setHeight(x, y, (getHeight(x, y-1) + getHeight(x, y+1) + 2*getHeight(x, y))/4.0);
}
} // x
} // y
} // pass
}
// smooth a part of the terrain.
void ShTlTerrainSceneNode::smoothVertex(s32 w, s32 h, s32 ww, s32 hh, f32 treshold, s32 pass)
{
if(w < 0){ w = 0; }
if(h < 0){ h = 0; }
if(w > Size.Width){ w = Size.Width; }
if(h > Size.Height){ h = Size.Height; }
if(ww < 0){ ww = 0;}
if(hh < 0){ hh = 0;}
if(ww > Size.Width){ ww = Size.Width; }
if(hh > Size.Height){ hh = Size.Height; }
if(w > ww) // switch values
{
s32 temp;
temp = w;
w = ww;
ww = temp;
}
if(h > hh) // switch values
{
s32 temp;
temp = h;
h = hh;
hh = temp;
}
for(int currentPass = 1; currentPass <= pass; currentPass++)
{
for(int y = h; y <= hh; y++){
for(int x = w; x <= ww; x++){
if(x > 0 && x < Size.Width){
if(fabs(getHeight(x, y) - (getHeight(x-1, y) + getHeight(x+1, y) + 2*getHeight(x, y))/4.0) >= treshold)
setHeight(x, y, (getHeight(x-1, y) + getHeight(x+1, y) + 2*getHeight(x, y))/4.0);
}
if(y > 0 && y < Size.Width){
if(fabs(getHeight(x, y) - (getHeight(x, y-1) + getHeight(x, y+1) + 2*getHeight(x, y))/4.0) >= treshold)
setHeight(x, y, (getHeight(x, y-1) + getHeight(x, y+1) + 2*getHeight(x, y))/4.0);
}
} // x
} // y
} // pass
}