MT4 crashes when ArrayResize - ???

 

Hello everybody and thanks for your help in advance.

I've got a dll function "MT4_mysql_fetch_row" that fetches a query from a db and puts the result in the string array "lsResult"! The problem is that MT4 crashes when it ArrayResizes the array afterwards ... how can that be?

   string lsResult[0];
   int liNumRow   = mysql_num_rows(liResult);
   int liNumField = mysql_num_fields(liResult);
   
   //prevent from resizing array to 0 => cashbot crashes
   if(liNumRow<1 || liNumField<1){
      mysql_free_result(liResult);
      return(FALSE);
   }
   
   ArrayResize(lsResult, liNumField);
   ArrayResize(sResultSet, liNumRow);

   for (i = 0; i < liNumRow; i++){
      MT4_mysql_fetch_row(liResult, lsResult);        //get fields of one row in array lsResult - after this ArrayInitialize and ArrayResize of "lsResult" does not work
      for (j = 0; j < liNumField; j++){
           sResultSet[i][j] = lsResult[j];
           write_log("debug",i+","+j+":="+sResultSet[i][j]);
      }
   }
   
   write_log("debug","1 initialized elements: "+ArrayInitialize(lsResult,0));          //will not initialize => return = -1
   
   mysql_free_result(liResult);
   
   write_log("debug","2 initialized elements: "+ArrayInitialize(lsResult,0));          //will not initialize => return = -1

   ArrayResize(lsResult, 0);                         <-------------------------- CRASH!!!
 
  1. You don't test the return code from ArrayResize
  2. try
    //string lsResult[0];
      string lsResult[];
  3. i don't know what
    MT4_mysql_fetch_row
    does with an uninitialized array of strings. Try setting all the array elements to a null string
    for(int iResult = 0; iResult < liNumField; iResult++) lsResult[iResult] = "";

 

Ok, this is tricky:

1. I did before and did not post the whole funktion it will post it below, with the debugging output.

2. I also tried this - no change

3. The given results in "lsResults" are correct and match the db entries, but after resizing MT4 crashes

I noticed the error when MT4 crashed and i recognized that it crashes after the second execution of the function with other db values fetched just when it tries to resize the just declared array. Althought the array "lsResults" should be initialized again because its declared IN the function ther seems to be som bullshit in the array ...

However, the question ist this how could it be, that mt4 crashes after a array is tried to resize after beeing handed over to a dll??? Even if the dll returns exact answers ...

Here the code of the function:

//fetches in a 2 dimensional array
int MySQL_FetchArray(string sQuery, string &sResultSet[][]){
   
   int i,j;
   if (DBconnected == FALSE) return(FALSE);
   
   write_log("debug",sQuery);
   
   int liLength= StringLen(sQuery);    
   mysql_real_query(mysql, sQuery, liLength);
   
   int liResult = mysql_store_result(mysql);
   if (liResult <= 0){      
      return(MySQL_NoError());
   }
   
   string lsResult[];
   //ArrayInitialize(lsResult,0);
   //lsResult[0]="";
   int liNumRow   = mysql_num_rows(liResult);
   int liNumField = mysql_num_fields(liResult);
   
   //prevent from resizing array to 0 => cashbot crashes
   if(liNumRow<1 || liNumField<1){
      mysql_free_result(liResult);
      return(FALSE);
   }
   
   write_log("debug","liNumField: "+liNumField);
   write_log("debug","liNumRow: "+liNumRow);
   write_log("debug","lsResult: "+lsResult[0]);
   write_log("debug","lsResult Size: "+ArraySize(lsResult));
   int a = ArrayResize(lsResult, liNumField);
   write_log("debug","liNumField resizing done a="+a);
   a = ArrayResize(sResultSet, liNumRow);
   write_log("debug","Array resizing done");

   for (i = 0; i < liNumRow; i++){
      for(int iResult = 0; iResult < liNumField; iResult++) lsResult[iResult] = "";
      MT4_mysql_fetch_row(liResult, lsResult);        //get fields of one row in array lsResult
      for (j = 0; j < liNumField; j++){
           sResultSet[i][j] = lsResult[j];
           write_log("debug",i+","+j+":="+sResultSet[i][j]);
      }
   }
   
   write_log("debug","1 initialized elements: "+ArrayInitialize(lsResult,0));
   
   mysql_free_result(liResult);
   
   write_log("debug","2 initialized elements: "+ArrayInitialize(lsResult,0));

   for (j = 0; j < liNumField; j++){
        sResultSet[0][j] = lsResult[j];
        write_log("debug",0+","+j+":="+sResultSet[0][j]);
   }

   ArrayResize(lsResult, 0);
   
   write_log("debug","Resizing done!");
   
   if(MySQL_NoError()==TRUE){
      return(liNumRow);
   }else{
      return(FALSE);
   }
}

log output from downside to up:

2012-03-28 19:59:19 0,8:=0

2012-03-28 19:59:19 0,7:=42

2012-03-28 19:59:19 0,6:=1.33085

2012-03-28 19:59:19 0,5:=23

2012-03-28 19:59:19 0,4:=0

2012-03-28 19:59:19 0,3:=1.33025

2012-03-28 19:59:19 0,2:=1.33025

2012-03-28 19:59:19 0,1:=1.33165

2012-03-28 19:59:19 0,0:=1800291495

2012-03-28 19:59:19 2 initialized elements: -1

2012-03-28 19:59:19 1 initialized elements: -1

2012-03-28 19:59:19 0,8:=0

2012-03-28 19:59:19 0,7:=42

2012-03-28 19:59:19 0,6:=1.33085

2012-03-28 19:59:19 0,5:=23

2012-03-28 19:59:19 0,4:=0

2012-03-28 19:59:19 0,3:=1.33025

2012-03-28 19:59:19 0,2:=1.33025

2012-03-28 19:59:19 0,1:=1.33165

2012-03-28 19:59:19 0,0:=1800291495

2012-03-28 19:59:19 Array resizing done

2012-03-28 19:59:19 liNumField resizing done a=9

2012-03-28 19:59:19 lsResult Size: 0

2012-03-28 19:59:19 lsResult: 1

2012-03-28 19:59:19 liNumRow: 1

2012-03-28 19:59:19 liNumField: 9

2012-03-28 19:59:19 SELECT ticket,min,max,reachVal,rvReached,closeDrop,maxLossTick,magicInt,orderLnk FROM orders WHERE present=1

Reason: