Constructor of a structure object is being called inside a working indicator and I'm not asking for that.

 

Hello.

So I have an indicator and a structure I'm using in it.

In OnChartEvent() function I call for some function of the structure. This function changes some variables inside the structure object.

It works for the first time, and for the second one constructor of the structure object is called for some reason (and the indicator stops working). The reason why I think this happens is because all variables start to contain the values I've put inside the constructor. Or they start to contain 0 when I don't use the explicit constructor.

My structure is pretty massive, with lots of other structures, functions, and arrays inside it, but I believe that my code is equal to the one below (though I didn't check the equality yet):

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         Label1Buffer[];

struct s{int num;
         void func();
         s() {num = 0;};
         } S;
         
void s::func(void)
   {
      Alert("a = ", num);
      num++;
   }
   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id == CHARTEVENT_KEYDOWN)
      {
         if(sparam == (string) 49) //49 is the code for the N-button
            {
               S.func();
            }
      }
  }
//+------------------------------------------------------------------+

Unlike my code, the code above works correctly: each time you press the N-button the value of the variable 'num' becomes bigger by 1.


So, can anyone tell me, please, is there some well known issue that might be related to my case or I should better look into my code?


Also, I'm not sure, but I believe that everything was working fine on Friday and on Saturday the same code started to act like I described.


Thank you.

 
Mikhail Sobolev: r the second one constructor of the structure object is called for some reason

You state it but do not provide any evidence.

Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
          Code debugging - Developing programs - MetaEditor Help
          Error Handling and Logging in MQL5 - MQL5 Articles (2015)
          Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
          Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

Mikhail Sobolev: Unlike my code, the code above works correctly:

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked, so we can't see your machine.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.

Always post all relevant code (using Code button) or attach the source file.

 
William Roeder #Use the debugger or print out your variables, including _LastError and prices and find out why.
This is interesting, thanks.
    William Roeder #Do you really expect us to debug your code for you?
No, of course not, I don't want to disturb you that much. That's why I didn't post my code.
    William Roeder #: Do you really expect an answer?    

For the question 'Is there some well known issue that might be related to my case?' - yes.

Since you did not mention 'the well known issue', I guess there is none. I've got the answer.

And then I've found the problem. It was so stupid, lol! I'm sorry.


Thank you anyway.