I am able to consistently replicate a crash that occurs when Phidget21.dll calls ntdll. The crash occurs in a background thread while my application is idle.
Here's the order of events: plug in a PhidgetInterfaceKit 8/8/8, plug in a PhidgetInterfaceKit 2/2/2 (both through the same hub), I run my application, application opens both interfacekits and waits for attachment, application creates another interfacekit instance, application waits for attachment (which never occurs because there are only two devices), application closes the third interfacekit instance. When application opens a second form and user moves the mouse, the application quickly crashes.
By attaching to the application with a debugger before it crashes, I am able to determine that Phidgets21.dll is calling EnterCriticalSection in ntdll
(ntdll.dll!_RtlEnterCriticalSection@4() + 0x1b577 bytes_) when the crash occurs. The crash is either an access violation (0xC0000005) or an invalid handle (0xC0000008) exception. In the call stack, I can see the addresses of the Phidget21.dll code making function calls. Going up the stack, the address offsets (relative to base) are: 0x7d8c, 0x7df9, and 0x4fdec. (using the latest drivers, dll date is 2/2/2016.) Is a symbol file (pdb) available for this dll?
Note, my second form uses a large background image. For reasons I don't understand, when I remove this image, the application stops crashing. The code for displaying a background image is created by the Visual Studio designer and is managed (C#) code, so I don't think that this code can be wrong. My best guess is that displaying the background image allocates a large buffer to hold the image and this causes garbage collection that affects Phidget21.NET.dll, or possibly it is reusing memory previously freed by Phidget21.dll and code in the dll is still using the memory even though it was freed.
Do you have any suggestions on how I can work around this problem?