TerminalInfoInteger causes abnormal terminations (sometimes)

 

I have a program where I check TerminalInfoInteger to get keystates of buttons in Timer. However, sometimes when I remove the EA, seems that if I catch them in mid-execution they get stuck and cause abnormal termination. Is it a mt5 bug? Or is there a way to solve it? How should I report it?

This is the "minimum" code to cause the error (the program where I use it is quite bigger but the effect is the same):

void OnInit()
{

   EventSetMillisecondTimer(10);
}

void OnTimer(void)
{
   Print("Input timer 1");
   TerminalInfoInteger(TERMINAL_KEYSTATE_UP);
   TerminalInfoInteger(TERMINAL_KEYSTATE_DOWN);
   TerminalInfoInteger(TERMINAL_KEYSTATE_LEFT);
   TerminalInfoInteger(TERMINAL_KEYSTATE_RIGHT);
   Print("Input timer 2");
   TerminalInfoInteger(TERMINAL_KEYSTATE_SHIFT);
   TerminalInfoInteger(TERMINAL_KEYSTATE_CONTROL);
   TerminalInfoInteger(TERMINAL_KEYSTATE_ENTER);
   TerminalInfoInteger(TERMINAL_KEYSTATE_ESCAPE);
   Print("Input timer 3");
   TerminalInfoInteger(TERMINAL_KEYSTATE_DELETE);
   TerminalInfoInteger(TERMINAL_KEYSTATE_INSERT);
   TerminalInfoInteger(TERMINAL_KEYSTATE_TAB);
   TerminalInfoInteger(TERMINAL_KEYSTATE_HOME);
   Print("Input timer 4");
   TerminalInfoInteger(TERMINAL_KEYSTATE_END);
   TerminalInfoInteger(TERMINAL_KEYSTATE_PAGEUP);
   TerminalInfoInteger(TERMINAL_KEYSTATE_PAGEDOWN);
   TerminalInfoInteger(TERMINAL_KEYSTATE_MENU);
   Print("Input timer 5");
   TerminalInfoInteger(TERMINAL_KEYSTATE_CAPSLOCK);
   TerminalInfoInteger(TERMINAL_KEYSTATE_NUMLOCK);
   TerminalInfoInteger(TERMINAL_KEYSTATE_SCRLOCK);

   Print("Input timer end");
}

void OnDeinit(const int reason)
{

   Print("DeInit");

   EventKillTimer();
}

After some tries running the EA and removing it, an abnormal termination would happen. Notice how it happens inside the function, since not all prints are logged. They also seem to get way slower if you check the logging times


 
Seems that a way to solve it would be to add a IsStopped() check between each call, but still looks pretty wrong to me (and still that makes for significantly slower removals)
 
Manuel Alejandro Cercos Perez:

I have a program where I check TerminalInfoInteger to get keystates of buttons in Timer. However, sometimes when I remove the EA, seems that if I catch them in mid-execution they get stuck and cause abnormal termination. Is it a mt5 bug? Or is there a way to solve it? How should I report it?

This is the "minimum" code to cause the error (the program where I use it is quite bigger but the effect is the same):

After some tries running the EA and removing it, an abnormal termination would happen. Notice how it happens inside the function, since not all prints are logged. They also seem to get way slower if you check the logging times


OnDeinit() has a runtime limit, which is 2500 ms. If you hit that limit, you get the error "Abnormal termination" printed in the logs.

The actual question is, why does it take so long to retrieve the values from the terminal.

My guess is, the moment you remove the EA, the terminal stalls the calls to TerminalInfoInteger and therefore hits the execution limit of OnDeinit.

In turn, this would explain the "Abnormal termination" notice in the log.

Questionable if this could be seen as a bug in the terminal itself. Further investigation would probably be required to make a claim and report it to MQ.
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Dominik Egert #:
OnDeinit() has a runtime limit, which is 2500 ms. If you hit that limit, you get the error "Abnormal termination" printed in the logs.

The actual question is, why does it take so long to retrieve the values from the terminal.

My guess is, the moment you remove the EA, the terminal stalls the calls to TerminalInfoInteger and therefore hits the execution limit of OnDeinit.

In turn, this would explain the "Abnormal termination" notice in the log.

Questionable if this could be seen as a bug in the terminal itself. Further investigation would probably be required to make a claim and report it to MQ.

Only seems to happen with keystate checks (other terminalinfointegers run faster). By what I saw in the profiler when searching for the bug, that function seemed already to be quite costly, but not so much to take more than half a second per call. Something internally seems to interfere when removing the EA... some looped check that triggers when the removal flag is set, a change in process priority, or who knows

Coincidentally, I already found another bug recently (which I reported to service desk too but still with no answer) in a function that also makes use of winuser.h (according to the documentation, TerminalInfoInteger for keystates calls GetKeyState and TranslateKey calls ToUnicodeEx). Maybe it's just a coincidence, or microsoft changed something about that file, or whoever was tasked with making winuser functions for metatrader whenever they were implemented didn't use them well and nobody noticed for years

Documentación para MQL5: Constantes, Enumeraciones y Estruturas / Estado de entorno / Estado del terminal de cliente
Documentación para MQL5: Constantes, Enumeraciones y Estruturas / Estado de entorno / Estado del terminal de cliente
  • www.mql5.com
Estado del terminal de cliente - Estado de entorno - Constantes, Enumeraciones y Estruturas - Manual de referencia de MQL5 - manual de usuario para el lenguaje del trading algorítmico/automático para MetaTrader 5