Crash Heeeeelp! going gone

 
There has been a critical error
Time : 2010.02.18 14:41
Program : Client Terminal
Version : 4.00 (build: 225, 10 Jul 2009)
OS : Windows XP Professional 5.1 Service Pack 2 (Build 2600)
Processors : 1 x X86 (level 15)
Memory : 1047024/587696 kb
Exception : C0000005
Address : 601817B1
Access Type : read
Access Addr : 033E9C68

Registers : EAX=00253DEF CS=001b EIP=601817B1 EFLGS=00010247
: EBX=FFFFFFFF SS=0023 ESP=0214A0A0 EBP=0214B8E8
: ECX=77C604D0 DS=0023 ESI=00E27438 FS=003b
: EDX=00000001 ES=0023 EDI=00000074 GS=0000

Stack Trace : 004588B5 00463E17 00455691 FFFFFFFF
: 00000000 00000000 00000000 00000000
: 00000000 00000000 00000000 00000000
: 00000000 00000000 00000000 00000000

Modules :
1 : 00400000 002B1000 c:\program files\metatrader - alpari uk\terminal.exe
2 : 20000000 002C5000 c:\windows\system32\xpsp2res.dll
3 : 5AD70000 00038000 c:\windows\system32\uxtheme.dll
4 : 5B860000 00054000 c:\windows\system32\netapi32.dll
5 : 60180000 0000B000 c:\program files\metatrader - alpari uk\experts\libraries\jmax.dll
6 : 629C0000 00009000 c:\windows\system32\lpk.dll
7 : 662B0000 00058000 c:\windows\system32\hnetcfg.dll
8 : 67320000 0002F000 c:\progra~1\common~1\symant~1\antispam\asoehook.dll
9 : 68040000 00008000 c:\program files\metatrader - alpari uk\experts\libraries\ptstdll.dll
10 : 71A50000 0003F000 c:\windows\system32\mswsock.dll
11 : 71A90000 00008000 c:\windows\system32\wshtcpip.dll
12 : 71AA0000 00008000 c:\windows\system32\ws2help.dll
13 : 71AB0000 00017000 c:\windows\system32\ws2_32.dll
14 : 72D10000 00008000 c:\windows\system32\msacm32.drv
15 : 72D20000 00009000 c:\windows\system32\wdmaud.drv
16 : 73DD0000 000FE000 c:\windows\system32\mfc42.dll
17 : 74720000 0004B000 c:\windows\system32\msctf.dll
18 : 74D90000 0006B000 c:\windows\system32\usp10.dll
19 : 755C0000 0002E000 c:\windows\system32\msctfime.ime
20 : 76380000 00005000 c:\windows\system32\msimg32.dll
21 : 76390000 0001D000 c:\windows\system32\imm32.dll
22 : 763B0000 00049000 c:\windows\system32\comdlg32.dll
23 : 76B40000 0002D000 c:\windows\system32\winmm.dll
24 : 76C30000 0002E000 c:\windows\system32\wintrust.dll
25 : 76C90000 00028000 c:\windows\system32\imagehlp.dll
26 : 76FD0000 0007F000 c:\windows\system32\clbcatq.dll
27 : 77050000 000C5000 c:\windows\system32\comres.dll
28 : 77120000 0008C000 c:\windows\system32\oleaut32.dll
29 : 77260000 000A0000 c:\windows\system32\urlmon.dll
30 : 773D0000 00102000 c:\windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
31 : 774E0000 0013D000 c:\windows\system32\ole32.dll
32 : 77920000 000F3000 c:\windows\system32\setupapi.dll
33 : 77A80000 00094000 c:\windows\system32\crypt32.dll
34 : 77B20000 00012000 c:\windows\system32\msasn1.dll
35 : 77BD0000 00007000 c:\windows\system32\midimap.dll
36 : 77BE0000 00015000 c:\windows\system32\msacm32.dll
37 : 77C00000 00008000 c:\windows\system32\version.dll
38 : 77C10000 00058000 c:\windows\system32\msvcrt.dll
39 : 77D40000 00090000 c:\windows\system32\user32.dll
40 : 77DD0000 0009B000 c:\windows\system32\advapi32.dll
41 : 77E70000 00091000 c:\windows\system32\rpcrt4.dll
42 : 77F10000 00047000 c:\windows\system32\gdi32.dll
43 : 77F60000 00076000 c:\windows\system32\shlwapi.dll
44 : 77FE0000 00011000 c:\windows\system32\secur32.dll
45 : 7C360000 00056000 c:\windows\system32\msvcr71.dll
46 : 7C800000 000F4000 c:\windows\system32\kernel32.dll
47 : 7C900000 000B0000 c:\windows\system32\ntdll.dll
48 : 7C9C0000 00815000 c:\windows\system32\shell32.dll

Call stack :



What does all that mean? I have obviously done sosmething wrong with an experimental DLL but I don't have a clue what to do about it. Any help would be appreciated.

 
I think I fixed it but can someone explain why. It crashes when there is a static double array defined in the DLL. Are static arrays not allowed? Removing the static qualifier made it work.
 
Ruptor:
I think I fixed it but can someone explain why. It crashes when there is a static double array defined in the DLL. Are static arrays not allowed? Removing the static qualifier made it work.

Can you post a section of the code? And the answer might depend on which C compiler you are using. Each tick in an EA is handled by a different (i.e. disposable) thread. Therefore, each call to your DLL comes from a different thread. Therefore, a static variable in the DLL involves memory being shared across threads. It's possible that your compiler is allocating the array as some sort of thread-local storage.

 
jjc:

[...] And the answer might depend on which C compiler you are using.[...]

This sort of scenario hadn't occurred to me before, because in a situation like yours I would simply make the variable global rather than static. The forum at http://www.velocityreviews.com/forums/t316858-static-variable-thread-safe.html is implying that all C compilers will make a static variable thread-specific. This is presumably one of the arcane parts of the C language specification.

 
Thanks for your input jjc. I only have one call to the DLL in the EA so doesn't that mean the DLL is only active on one thread?
 
Ruptor:
Thanks for your input jjc. I only have one call to the DLL in the EA so doesn't that mean the DLL is only active on one thread?

Not in my experience. From what I've seen - see above - MT4 creates a new thread to process each tick in an EA. In other words, it creates a disposable thread whose sole purpose and lifetime is to transmit that tick to a particular EA. Therefore, each call to a DLL comes from a different thread. MT4 does not allocate one thread per EA for the whole of the EA's lifetime. From what I've seen.

 

Oh well the static wasn't the answer because every run since the one run good also crashes and now I am not sure I did get a successful run. Basically it still crashes. What should I look for? What are common problems that could make DLLs crash MT4?

 
Ruptor:

[...] What are common problems that could make DLLs crash MT4?

The answer is almost always memory access, in one form or another.


If using a global (i.e. per-process) variable definitely isn't working, try moving to a model where the EA has to call a function in its init() which allocates a block of memory and returns some sort of handle. The EA then gives the DLL this handle in all the calls which it makes during start(). And then frees the memory by calling some sort of release function in deinit().

 
Ok Thanks jjc I shall look in to it but it seems like this is going to be a long one.
 
jjc:

The answer is almost always memory access, in one form or another. [...]

...And exception C0000005 pretty much confirms it. I'm still surprised that declaring the array as global (and non-static) doesn't fix the problem. Unless you have more than one problem, and you've now moved on to a new one.

Reason: