Once i click button EA Runs in to access violation error.

 

Hello, Having one issue everything seems ok untill it goes through StringSplit function.

Can anyone please help?

//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {

    Alert("ok");
      
    m_sep = StringGetCharacter(sepChar,0); 
    string mystring = sparam;
       
    Print(sparam);
    int k = StringSplit(mystring,m_sep,resultArr);

// IT NEVER GETS IN TO THIS LOOP

    if(k>0) 
    { 
      for(int i=0;i<k;i++) 
        { 
         PrintFormat("result[%d]=%s",i,resultArr[i]); 
        } 
     }

    int return = StringFind(sparam,"Quants_Clearer",0);

  }
 
If i comment out the stringsplit then error does not occur. Cannot figure out whats wrong here is how sepChar and m_sep are defined.

string sepChar="_"; 
ushort m_sep;
 
Ferhat Mutlu:
If i comment out the stringsplit then error does not occur. Cannot figure out whats wrong here is how sepChar and m_sep are defined.

try replacing mystring with a fixed string like "hello_world"  and see if the problem is solved. In which case it is something to do with the &sparam being passed.

try declaring the array and the character locally to rule out any issues there...

 
Paul Anscombe:

try replacing mystring with a fixed string like "hello_world"  and see if the problem is solved. In which case it is something to do with the &sparam being passed.

try declaring the array and the character locally to rule out any issues there...

I have replaced the mystring with "Hello_world" no the issue remains same.
Declared the array and characters locally same issue happens.

both of this ways not worked :( tnx for help.

The ea runs with OnTimer is that may creating the issue? Totally lost.

 
Ferhat Mutlu:

I have replaced the mystring with "Hello_world" no the issue remains same.
Declared the array and characters locally same issue happens.

both of this ways not worked :( tnx for help.

The ea runs with OnTimer is that may creating the issue? Totally lost.

are you able to post the whole thing, then it can be run to rule out your environment

and are you on the latest version of MT4

 
Paul Anscombe:

are you able to post the whole thing, then it can be run to rule out your environment

and are you on the latest version of MT4

Im with a build of 1320.
Can't post the whole code its one of my clients. But i am literally sure the error at stringsplit.
OnTimer just executes the function and graphical design. I have buttons named properly but as seen above even with local string it went to fail.
Now i am generating new file to see if its going to happen will post that one here
 
Does the debugger help?
 
Ferhat Mutlu:
Im with a build of 1320.
Can't post the whole code its one of my clients. But i am literally sure the error at stringsplit.
OnTimer just executes the function and graphical design. I have buttons named properly but as seen above even with local string it went to fail.
Now i am generating new file to see if its going to happen will post that one here
//+------------------------------------------------------------------+
//|                                               StringSplitBug.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

input  string  Markets            = "EURUSD,EURJPY,EURAUD,EURNZD,EURCAD,GBPUSD,GBPJPY,GBPAUD,GBPNZD,GBPCHF,GBPCAD";

input  int     start_x            = 10;
input  int     start_y            = 100;
input  int     RowGap             = 20;

bool UseCombinedAlerts = false;

string sep=","; 
ushort u_sep;

string sepChar="_"; 
ushort m_sep;

string Pairs[];
string resultArr[];
string y[];

double LastAlert[][6];


datetime DateToStop = D'2020.12.23 00:00:00';

datetime Current_time;
datetime td_start,td_stop;
datetime sCurrent_time;
datetime st_start,st_stop;

bool gGoodTime;
bool IsFirstLoad = true;
string symbol;
double AlertLog[1];

bool UpAlert[][6];
bool DnAlert[][6];

datetime LoadBar;

int CustomPairIndex;

datetime LastAlertTime[][6];
int      LastBarDir[][6];
int      LastCrossDir[][6];
int      LastTdiCrossDir[][6];
int      Alerts[][6];
datetime LastAlertMarker[][6];

ENUM_TIMEFRAMES GlobalTF;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer

     ArrayInitialize(LastAlertTime,EMPTY_VALUE);
     ArrayInitialize(LastAlert,EMPTY_VALUE);
     ArrayInitialize(UpAlert,EMPTY_VALUE);
     ArrayInitialize(DnAlert,EMPTY_VALUE);
     ArrayInitialize(LastCrossDir,3);
     ArrayInitialize(LastBarDir,3);
     ArrayInitialize(LastTdiCrossDir,3);
     ArrayInitialize(Alerts,3);
     ArrayInitialize(LastAlertMarker,EMPTY_VALUE);
     ArrayFree(y);

     ObjectsDeleteAll(0,"Quants_");

     IsFirstLoad = true;

     EventSetMillisecondTimer(5);

     
     u_sep=StringGetCharacter(sep,0);
     int k=StringSplit(Markets,u_sep,Pairs);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
      button_create("Quants_All_Delete",430,28,80,30,"DELETE ALL","DELETE ALL",clrWhite,clrGray,6,false);
      
       
       for(int i = 0; i <= 5; ++i)
       {
         switch(i)
         {
   
            case 1: 
            TDI1(PERIOD_M5);
            break;
            case 2:
            TDI1(PERIOD_M15);
            break;
            case 3:
            TDI1(PERIOD_M30);
            break;
            case 4:
            TDI1(PERIOD_H1);
            break;
            default:
            break; 
         }
         
       }
   
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---    
        Alert("ok");
       

        m_sep = StringGetCharacter(sepChar,0); 
        string mystring = sparam;
       ArrayResize(resultArr,10000);
       
       Print(sparam);
        int k = StringSplit(sparam,m_sep,resultArr);
   
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------------------------------------------------------------------+    
int TDI1(ENUM_TIMEFRAMES _TimeFrame)
  { 
    /*  if(!_IsNewBar)
      return 0;
  */       
          

      
      int temp_y = 0;
      int size = ArraySize(Pairs);
      int Positioner = 0;
      int TFindex = 0;
      
      if(IsFirstLoad)
      {
        ArrayResize(LastAlert,size,3);
        ArrayResize(Alerts,size,3);
        ArrayResize(LastAlertTime,size,3);
        ArrayResize(LastBarDir,size,3);
        ArrayResize(LastCrossDir,size,3);
        ArrayResize(LastTdiCrossDir,size,3);
        ArrayResize(LastAlertMarker,size,EMPTY_VALUE);
      }
      
          

      for(int pair = 0; pair < ArraySize(Pairs) ; pair++ )
      {    
         symbol = Pairs[pair];  
         
         switch(_TimeFrame)
         {
            case PERIOD_M5:           
            Positioner = 178;
            TFindex = 1;
            break;
            case PERIOD_M15:
            Positioner = 283;
            TFindex = 2;
            break;
            case PERIOD_M30:
            Positioner = 398;
            TFindex = 3;
            break;
            case PERIOD_H1:
            Positioner = 508;
            TFindex = 4;
            break;
            default:
            break;    
         }

        
        button_create("Quants_Clearer"+"_"+IntegerToString(pair)+"_"+TFindex,start_x+Positioner+75, start_y+temp_y+3, 17, 17,"X","" , clrWhite, clrGray, 7, false);    
        
             temp_y+=RowGap;

      } 
      
      return 0;
    }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void button_create(string name, int offX, int offY, int width, int height,
                  string text, string tip, color clr1, color clr2, int font_size=10,bool _State = false)
 {

    ObjectCreate(name, OBJ_BUTTON, 0, 0, 0);
    ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
    ObjectSetInteger(0, name, OBJPROP_XDISTANCE,    offX);
    ObjectSetInteger(0, name, OBJPROP_YDISTANCE,    offY);
    ObjectSetInteger(0, name, OBJPROP_XSIZE,        width);
    ObjectSetInteger(0, name, OBJPROP_YSIZE,        height);

    ObjectSetString( 0, name, OBJPROP_FONT,         "Arial");
    ObjectSetInteger(0, name, OBJPROP_FONTSIZE,     font_size);
    ObjectSetString( 0, name, OBJPROP_TEXT, text);
    ObjectSetInteger(0, name, OBJPROP_COLOR, clr1);  // Text color
    ObjectSetString( 0, name, OBJPROP_TOOLTIP, "");

    ObjectSetInteger(0, name, OBJPROP_BGCOLOR,      clr2);
    ObjectSetInteger(0, name, OBJPROP_CORNER,       CORNER_LEFT_UPPER);

    ObjectSetInteger(0, name, OBJPROP_BORDER_COLOR, clrDarkGray);
    ObjectSetInteger(0, name, OBJPROP_BACK,         false);
    //--- enable (true) or disable (false) the mode of moving the button by mouse
    ObjectSetInteger(0, name, OBJPROP_STATE,        _State);
    ObjectSetInteger(0, name, OBJPROP_SELECTABLE,   false);
    ObjectSetInteger(0, name, OBJPROP_SELECTED,     false);
    ObjectSetInteger(0, name, OBJPROP_HIDDEN,       false);
    ObjectSetInteger(0, name, OBJPROP_ZORDER,       5);
 }
//+------------------------------------------------------------------+
Files:
 
Carl Schreiber:
Does the debugger help?

No. So weirdly above file gets compiled and executed correctly and it works without any problem.. But i get in to error with same functions in my original EA.
I just copy pasted the OnTimer and OnChart.. It works with this file while not working with previous one? weird.

The other one using several arrays 2d arrays. Is that running out of memory?
Both files have the same way with function calls and structure

 
Ferhat Mutlu:

No. So weirdly above file gets compiled and executed correctly and it works without any problem.. But i get in to error with same functions in my original EA.
I just copy pasted the OnTimer and OnChart.. It works with this file while not working with previous one? weird.

The other one using several arrays 2d arrays. Is that running out of memory?
Both files have the same way with function calls and structure

have you stepped through with the debugger as Carl suggested, you should do that.

also if you are using any dlls you may want to try it with them.

 
Paul Anscombe:

have you stepped through with the debugger as Carl suggested, you should do that.

also if you are using any dlls you may want to try it with them.

Let me see. No, There is not any dll attached to the file