Stack overflow Error ... without info on which section of code is causing this

 

Dear All

I have recently started getting  Stack overflow error but there is nothing to tell which code is causing this. How can I find the source is this problem. I have understood that this is caused by recursive loop. But unable to trace which loop is causing it.

debugger also did not help much to find it.

Until yesterday the code was working fine, and I have not made any changes to functions with loop.

2022.12.02 12:29:10.704 US30,Daily: history cache allocated for 455 bars and contains 453 bars from 2021.01.04 00:00 to 2022.09.30 00:00

2022.12.02 12:29:10.704 US30,Daily: 1 bar from 2022.10.03 00:00 added

2022.12.02 12:29:10.704 US30,Daily: history begins from 2021.01.04 00:00

2022.12.02 12:29:17.516 2022.10.03 02:48:00   Stack overflow

Look forward to solution.
Deep Neural Networks (Part VII). Ensemble of neural networks: stacking
Deep Neural Networks (Part VII). Ensemble of neural networks: stacking
  • www.mql5.com
We continue to build ensembles. This time, the bagging ensemble created earlier will be supplemented with a trainable combiner — a deep neural network. One neural network combines the 7 best ensemble outputs after pruning. The second one takes all 500 outputs of the ensemble as input, prunes and combines them. The neural networks will be built using the keras/TensorFlow package for Python. The features of the package will be briefly considered. Testing will be performed and the classification quality of bagging and stacking ensembles will be compared.
 
Anil Varma: I have recently started getting  Stack overflow error but there is nothing to tell which code is causing this. How can I find the source is this problem. I have understood that this is caused by recursive loop. But unable to trace which loop is causing it. debugger also did not help much to find it. Until yesterday the code was working fine, and I have not made any changes to functions with loop. Look forward to solution.

A stack overflow builds up over time, and can be caused by multiple functions, so it is not possible to narrow it down to a single incident.

It can usually be caused by uncontrolled function recursion (e.g. a function calling itself infinitely).

 
Fernando Carreiro #:

A stack overflow builds up over time, and can be caused by multiple functions, so it is not possible to narrow it down to a single incident.

It can usually be caused by uncontrolled function recursion (e.g. a function calling itself infinitely).

@Fernando Carreiro

Thanks a lot buddy.

Actually I figured it out as I was calling the function within the same function. It was recent change and I just guessed it could be cause. However if it has been some time and few changes have been done, I am worried I could be able to trace it. Wish MQL5 could point it.

Here is the error code for the other user's benefit on the forum.

CENUM_HA_BAR CiHAshi::GetHABarType(int pIndex) {

                if(HAOHLC[k].close < HAOHLC[k].open) {

                        if(HAOHLC[k].open == HAOHLC[k].high)                                                                                                                                    // BULLISH WHEN OPEN AND LOW EQUAL
                                return(BEARISH);
                        else
                        if(HAOHLC[k].open != HAOHLC[k].high && BodySizeRTA <= 0.05)                                             // BEAR DOJI WITH 5% BODY SIZE
                                return(BEAR_DOJI);
                        else
                        if(HAOHLC[k].open != HAOHLC[k].high && BodySizeRTA > 0.05 && BodySizeRTA <= 0.20)               // BEAR SPINNING TOP WITH 20% BODY SIZE
                                return(BEAR_STOP);
                        else
                        if(HAOHLC[k].open != HAOHLC[k].high && BodySizeRTA > 0.20 && UpperWickRTA <= 0.05)      // !BEARISH, !BEAR_DOJI, !BEAR_STOP
                                return(BEARISH);                                                                                                                                                                                                                                                                        // DEEMED BEARISH
                        else
                        if(HAOHLC[k].open != HAOHLC[k].high && BodySizeRTA > 0.20)                                              // BEARISH WEAK WITH BODY SIZE 20% OF AMPLITUDE
                                return(BEAR_WEAK);
                }

        if(GetHABarType(1) == BEAR_WEAK) {
                ... do something
        }
 
Anil Varma #: However if it has been some time and few changes have been done, I am worried I could be able to trace it. Wish MQL5 could point it.
As I have already explained, a "stack overflow builds up over time, and can be caused by multiple functions, so it is not possible to narrow it down to a single incident".
 

I use a "depth" measurement and track the max which i send in the recursive calls .

So , for example , if i know logically my max "depth" is 8 and it prints 21 then i check that function .

 
Anil Varma #:

@Fernando Carreiro

Thanks a lot buddy.

Actually I figured it out as I was calling the function within the same function. It was recent change and I just guessed it could be cause. However if it has been some time and few changes have been done, I am worried I could be able to trace it. Wish MQL5 could point it.

Here is the error code for the other user's benefit on the forum.

This code does not make much sense.

1. The function starts with an if statement which if true, returns to caller.
2. When the if from #1 is false, i.e. when the bar is a green (up) bar, the function then calls itself with a 1 bar index (do you intend to check the previous bar, or is it calling the first bar from left? in both cases, you can end up in infinite calling) - which in case it is also a green bar, it ends up calling itself endlessly. What is your intention here?

 
Amir Yacoby #: This code does not make much sense.

1. The function starts with an if statement which if true, returns to caller.
2. When the if from #1 is false, i.e. when the bar is a green (up) bar, the function then calls itself with a 1 bar index (do you intend to check the previous bar, or is it calling the first bar from left? in both cases, you can end up in infinite calling) - which in case it is also a green bar, it ends up calling itself endlessly. What is your intention here?

The OP explained that it was not his intention of calling the function itself. I believe it was simply a "typo" on his part which ended up causing the stack overflow. He has since then corrected the issue.
 
Fernando Carreiro #:
As I have already explained, a "stack overflow builds up over time, and can be caused by multiple functions, so it is not possible to narrow it down to a single incident".

Agree got your point Fernando

 
Fernando Carreiro #:
The OP explained that it was not his intention of calling the function itself. I believe it was simply a "typo" on his part which ended up causing the stack overflow. He has since then corrected the issue.

true ...

Reason: