AB hungs sometimes when in the editor I click the APPLY button

Hi

I am sure it has to do with a plugin I am working on. SOMETIMES (1 out of 30 maybe) Amibroker hungs when I make changes to the AB script and click the APPLY button.

Any ideas what I could look for?

I do not really mind restarting AB once in a while. This is not my problem. However this is a symptom telling me that something is wrong with my plugin, maybe not releasing memory, maybe writting something to RAM that is not supposed to...

I am not experienced in C++, and I know I should therefore avoid writting plugins.

  1. Try without your plugin.
  2. Place OutputDebugString in your plugin and use DebugView to get better insight into what your plugin is doing

Hi Tomasz

  1. I'll give it a try. However I assume the script will not hung if I remove my plugin. It does not hung consistently, so it is not easy to test this.
  2. From what I understand OutputDebugString/DebugView serves to examine the content of variables, correct? I am exporting all related data to a text file, in all key points of the script to do this.
  1. No I mean put OutputDebugString() in every function of your plugin (at entry and at exit) to know where it is when it hangs.
1 Like

Got it. Thanks, I will try this.

Hi @Tomasz

The problem occurs when I click the APPLY in the editor and Status(ActionEx) = 19. The plugin gets negative values for some array index parameters, nSize is reported to be 10 (from : int nSize = gSite.GetArraySize();). Which reminds me you have always said: "never assume the amount of bars.." or something like this.

So I modified the script and first I check for negative array index values, before I call the plugin. After that the problem disappeared.

lookback = Param( "Look back", 20, 1, 200, 1 );
shift = Param( "Shift", 0, 0, 300, 1 );

end_barindex = BarCount - 1 - shift;
start_barindex = end_barindex - lookback; 

zz = Null;

if (start_barindex>=0)    // I need to check for negative indexes, otherwise the DLL will hung
   zz = mypluginfunction( start_barindex, end_barindex, ...);

I am wondering, is this the right way to handle it?

This code is WRONG:

end_barindex = BarCount - 1 - shift;
start_barindex = end_barindex - lookback; 

Because it will produce NEGATIVE array indices and if you pass it to your DLL it will obviously cause access violation when you try to access non-existing array elements.

This is why you should NOT write DLLs. When you write in AFL, AmIbroker protects against out-of-bound array access. When you write in C++ you are out of luck. C++ does not protect you from anything and you are shooting yourself in the foot.

It was mentioned hundreds of times that you should NEVER assume anything about number of bars. BarCount can be as low as 1 and your plugin MUST handle it. You should always check array size and NEVER access array elements less than zero.
http://www.amibroker.com/kb/2014/09/22/do-not-make-assumptions-on-number-of-bars/

2 Likes