Getting _LastError = 4012 unexcpectedly immediate following the return from a Class method.

 

In my MQL5 EA, I have a class StatusReport that contains a method:   

 static void  TestReports().

In OnInit() I have a call to   

 StatusReport::TestReports();

Before the call to TestReports(), the  err = GetLastError(); returns 0.

At the end of TestReports(), before returning, the statement err = GetLastError(); returns 0;

Immediately following the return from TestReports(), the statement err = GetLastError(); returns 4012 (ERR_INVALID_POINTER). WHY?

If TestReports() had no _LastError just before the function return, why did OnInit() have a _LastError = 4012 immediately after the return from the call to:

StatusReport::TestReports();

Where did the _LastError pointer error (4012) come from following the return from the call to StatusReport::TestReports(); This call functions as it should.

Is there a better way to call a Method like TestReports(), defined within the class StatusReport ?

The MQL5 compiler required that the TestReports method with StatusReport  to have a static access class declaration.

Is this error caused by a BUG in the MQL5 runtime system that should not otherwise happen?

What is the best way to eliminate this error?

Any Help is much appreciated.


 
it’s almost certainly not a bug in MQL5, and not related to static .
You’re almost certainly hitting an invalid pointer / double-free in some destructor or hidden cleanup code that runs after your last line in TestReports()

void StatusReport::TestReports()
{
   // ...
   int err = GetLastError();             // 0 here
   // return;
}
int OnInit()
{
   ResetLastError();
   int err = GetLastError();             // 0

   StatusReport::TestReports();          // call

   err = GetLastError();                 // 4012 here
}

Before the call → 0 
Inside, just before return → 0 
After the call → 4012