MathUnique Mod Error

To add comments, please log in or register
17

Hello! Im trying to modify the MathUnique function from the Math library for multidimensional arrays and I keep getting an array out of bounds error. Anybody mind helping me figure out why? My code is as

follows

```bool MathUnique2(const double &array[][6],double &result[][6])
{
//--- check array size
int size=ArraySize(array);
if(size==0)
return(false);

//--- prepare additional array
bool checked[][6];
if(ArrayResize(checked,size)!=size)
return(false);
ArrayFill(checked,0,size*6,false);

//--- prepare result array
if(ArraySize(result)<size)
if(ArrayResize(result,size)!=size)
return(false);
//--- find unique elements
int unique_count=0;
double value1=0,value2=0,value3=0,value4=0,value5=0,value6=0;
for(;;)
{
bool flag=false;
for(int i=unique_count; i<size; i++)
{
if(!flag && !checked[i][0] && !checked[i][1] && !checked[i][2] && !checked[i][3] && !checked[i][4] && !checked[i][5])
{
value1=array[i][0];
value2=array[i][1];
value3=array[i][2];
value4=array[i][3];
value5=array[i][4];
value6=array[i][5];

result[unique_count][0]=array[i][0];
result[unique_count][1]=array[i][1];
result[unique_count][2]=array[i][2];
result[unique_count][3]=array[i][3];
result[unique_count][4]=array[i][4];
result[unique_count][5]=array[i][5];

unique_count++;

checked[i][0]=true;
checked[i][1]=true;
checked[i][2]=true;
checked[i][3]=true;
checked[i][4]=true;
checked[i][5]=true;

flag=true;
}
else
if(flag && value1==array[i][0])
{checked[i][0]=true;
}
if(flag && value2==array[i][1])
{checked[i][1]=true;
}
if(flag && value3==array[i][2])
{checked[i][2]=true;
}
if(flag && value4==array[i][3])
{checked[i][3]=true;
}
if(flag && value5==array[i][4])
{checked[i][4]=true;
}
if(flag && value6==array[i][5])
{checked[i][5]=true;
}
}
if(!flag)
break;
}
//--- resize target array
ArrayResize(result,unique_count);
//---
return(true);
}```
To add comments, please log in or register