Applies To:
  • CitectSCADA 1.00 1.01 1.10 1.11 1.20 2.00 2.01 3.00

Summary:
You may get the software error "Invalid Heap" if you call a DLL function via DLLCall which uses a large amount of stack. 

Solution:
When Citect calls a DLL function via DLLCall a new stack is created in the memory heap of Citect. The default size of this stack is 8K in version 3.x. If the function you are calling uses more stack than the default 8k, you will corrupt Citects memory heap. You may get the error message "Invalid Heap" or cause Citect to generate a GPF.

You may work around this problem by increasing the size of the stack with the parameter [Code]DLLStack. We suggest you increase the stack default from 8k to 20k. If you set the value of DLLStack too high (eg 32000), you will start to get the error "General Stack Overflow" as the DLL stack is allocated from Citects General Stack memory. The general stack is controlled by the option [General]Stack and defaults to 32000. If you get the "General Stack Overflow" error then reduce the size of the DLLStack.

You may verify that Citect heap is being corrupted by the DLL my setting the INI parameter [MEMORY]Segment=0. Then start up Citect and call your DLL function. Setting this option will cause Citect to allocate the stack in a separate memory segment. If the stack is overflowed when your DLL is called it will cause a stack fault in your DLL instead of corrupting Citects memory heap. You should only set the [MEMORY]Segment=0 on as a test, as it causes Citect to use much more memory and make your system run slower.

Citect version 4.10 and later no longer uses the heap for calling the DLL. We now use the same stack as Citect so there should be no stack corruption problems with these versions.

 

Keywords:
 

Attachments