Stex,
it is quite hard to help solving a problem under these circumstances. The thing you need to do, if you want to know where the problem comes from, is to find an easy way to reproduce the issue, better if it is with a small piece of code.
If this is not possible for your application (due to time, efforts,ecc.), you mentioned the error occurs only under particular conditions. The best thing you can do is to determine if these conditions can be prevented from happening. You may think of forcing the execution of your program not to fall under the conditions that are known to cause the problem
AlessioD