Access violation read (0x00000070), "Incorrect casting of pointers" etc. with Indicators

 

Since Build 1380, also with the current build 1400 we face this issue in MT4 that occurs either when changing the timeframe of an indicator or when terminating the indicator within the code. This is is clearly a BUG in MT4. 

That we talk about a bug is certain, since the code works without problems with the debugger. It also works with MT5, debug or optimized compile, and it occurs only "sometimes" and in dependance of the timeframe but only when not debugging and also not with every indicator, no matter all of them are based on the same and identical base-classes.

It started with this "Incorrect casting" thing, which is no bug in the code. The casting is correct. But already in the debugger I could see, that MT4 creates some hassle with the class-destructors, since it tries to call the destructor of the same object not only twice, rather 10 times or more. This function, which brings up the error of incorrect casting, is executed within many destructors to delete dynamically created objects. (By this way: Both, MT5 and MT4 sometimes report that objects were not deleted, sometimes, no matter that the code is always the same. In general there seem to be something going wrong with the destruction process.)

Then I started to set Print outputs to see, where the problem exactly occurs. Funnywise, some Print-outputs never show up, or are dropped, since outputs which were triggered a function "later", are visible. 

Please dont ask for a sample code, we talk about at least 25.000 lines of code which is all nested in complex base-classes. And nevertheless, it does not happen with all such indicators, which are all based on the same basis-code, even when the code is almost identical. This all makes no sense at all. 



As you can also see: Again and again this comes up with MetaTrader 4 - and it was never a bug in the code. 
https://www.mql5.com/en/forum/337828

Access violation read - once again - crashes MT4
Access violation read - once again - crashes MT4
  • 2020.04.17
  • www.mql5.com
Build: 1260 Its caused by an indicator, which works perfectly on its first start, and the error occurs when the timeframe is changed...
 
Doerk Hilger:

Since Build 1380, also with the current build 1400 we face this issue in MT4 that occurs either when changing the timeframe of an indicator or when terminating the indicator within the code. This is is clearly a BUG in MT4. 

That we talk about a bug is certain, since the code works without problems with the debugger. It also works with MT5, debug or optimized compile, and it occurs only "sometimes" and in dependance of the timeframe but only when not debugging and also not with every indicator, no matter all of them are based on the same and identical base-classes.

It started with this "Incorrect casting" thing, which is no bug in the code. The casting is correct. But already in the debugger I could see, that MT4 creates some hassle with the class-destructors, since it tries to call the destructor of the same object not only twice, rather 10 times or more. This function, which brings up the error of incorrect casting, is executed within many destructors to delete dynamically created objects. (By this way: Both, MT5 and MT4 sometimes report that objects were not deleted, sometimes, no matter that the code is always the same. In general there seem to be something going wrong with the destruction process.)

Then I started to set Print outputs to see, where the problem exactly occurs. Funnywise, some Print-outputs never show up, or are dropped, since outputs which were triggered a function "later", are visible. 

Please dont ask for a sample code, we talk about at least 25.000 lines of code which is all nested in complex base-classes. And nevertheless, it does not happen with all such indicators, which are all based on the same basis-code, even when the code is almost identical. This all makes no sense at all. 



As you can also see: Again and again this comes up with MetaTrader 4 - and it was never a bug in the code. 
https://www.mql5.com/en/forum/337828

Small mistake from my side: 

Removing indicator within the code works with build 1400, the message "Incorrect casting" does not appear anymore. But the "Access violation" message stays. 

 

Given that MT4 is no longer actively developed, I believe that the only way to have the developers seriously look at it will be to:

  1. Contact the Service Desk with the issue, with a link to this topic.
  2. Supply a piece of code that can replicate the issue.

Without any sample code to replicate it, they will just ignore it.

So, given that your original code is too large, you will have to code something new and short that is able to reproduce the issue.

However, given that there are rumours going around that MetaQuotes might be dropping MT4 in the coming year, please consider that it probably will not be addressed.

 
Fernando Carreiro #:

Given that MT4 is no longer actively developed, I believe that the only way to have the developers seriously look at it will be to:

  1. Contact the Service Desk with the issue, with a link to this topic.
  2. Supply a piece of code that can replicate the issue.

Without any sample code to replicate it, they will just ignore it.

So, given that your original code is too large, you will have to code something new and short that is able to reproduce the issue.

However, given that there are rumours going around that MetaQuotes might be dropping MT4 in the coming year, please consider that it probably will not be addressed.

I hope they would drop this obsolete mf which is just annoying us anyway all the time.

In view of the sample: How can I create a sample when the bug is not even showing up with all the final codes. I can obfuscate some real code, no problem, but last they also just shrugged and meant "very nested". Yeah, nesting happens ;)

Service Desk? There is service desk???

 
Doerk Hilger #: Service Desk? There is service desk???

Have you never used it or seen it in your profile panel?

There are two common places to find it ...

  1. At the bottom of almost every page, in the footer section, there is a link — Contacts and requests

  2. When you go to your profile page, on the left there is a menu panel with a link to the Service Desk.
    Here is my profile as an example ...

Contact Us
Contact Us
  • www.mql5.com
Send your messages and see the history of your requests to the mql5.com support team even if you are not registered on the website.
 

Sure, but I remember they just gave up any support service and led just everyone to the forum:


 
Doerk Hilger:

Since Build 1380, also with the current build 1400 we face this issue in MT4 that occurs either when changing the timeframe of an indicator or when terminating the indicator within the code. This is is clearly a BUG in MT4. 


I use multiple nested classes with the deletion of large numbers dynamic objects in the destructor without issue - I know that does not help you but it highlights that your problem is not a consistent one

As for mt4 they should kill it, this limbo of no updates/development. But product creators needing to include mt4 because of the user base is just crazy 
 
Paul Anscombe #:
I use multiple nested classes with the deletion of large numbers dynamic objects in the destructor without issue - I know that does not help you but it highlights that your problem is not a consistent one


... or that that is not the problem. As mentioned: Lots of Indicators based on the same classes, using the same functions dont have the problem either. That also doesn´t help me.

But this behavior with the multiple executions of destructors is completely weird nonetheless, as well as the "Incorrect casting", which is just not a correct error. And by the way also popped up again with 1400. 

 
Doerk Hilger #:

... or that that is not the problem. As mentioned: Lots of Indicators based on the same classes, using the same functions dont have the problem either. That also doesn´t help me.

But this behavior with the multiple executions of destructors is completely weird nonetheless, as well as the "Incorrect casting", which is just not a correct error. And by the way also popped up again with 1400. 

Can you show the code that gives "Incorrect casting".

For tracing new and delete there is a code (for mql5) to trace these calls, maybe this gives some insight.

Should be adaptable to mql4.

 
Dominik Egert #:
Can you show the code that gives "Incorrect casting".

For tracing new and delete there is a code (for mql5) to trace these calls, maybe this gives some insight.

Should be adaptable to mql4.

The code is shown in the first posting. But, when the error pops up sometimes, and even not every time the same code is used (we talk bout 30-40 indicators), it shouldn´t be a matter of the code. Fun fact on top: After the error occurs, the indicator is still loaded but not active anymore.

 
You can try to add a check of object pointers before the object assignment, like this
T *test=dynamic_cast<T *>(Object[i]);
if(test==NULL) 
   PrintFormat("Error in object type casting. Object type is: %s test type is: %s",typename(Object[i]),typename(T));
Reason: