On 27/11/2014 at 11:35, xxxxxxxx wrote:
Hi Pim,
now it will get messy... :wink:
What you are describing are the typical problems you run into with threading (unless doing it right, I should add, but this is not meant as an insult in any way). Threading is probably one of the hardest topics to come to grips with. And searching for bugs can be a pain, as the the code that did something wrong most likely ran a while ago and is history when the resulting bug occurs.
Having this said, it will be very hard for an outstanding person to point you to the culprit.
One pitfall may be calling an API function in a thread context, that is not allowed to run in a thread context. The SDK docs have an article on this (which is not all complete, but may nevertheless give good hints) : R15 SDK Docs: Important Threading Information
Although you should pay attention to any notes in SDK docs on the functions you use in your thread.
Another thing is memory corruption and/or concurrent access to data structures. Your global variables may well be suspect here. With threads you always have to be aware that at any given time two functions or code lines may access data they share. You need to closely inspect your code, if this can happen. And if so, you'll need some mechanism of serialization, catchwords like mutex and semaphore come to mind.
Then there's something you say, that makes me skeptical:
I am using some delays to give the dialog time to display the bitmap
This should not be needed, if you are doing it right. Many programmers try to mask race conditions with delays, in the hope, if they only make the chances small enough it will never happen. By experience I can tell, it will happen anyway. You need to cure the race condition, nothing else will help.
Finally in my article about debugging plugins on our new PluginCafe blog (Debugging Cinema 4D Plugins Written in C++), I have a small section about multithreading. There are some links under "Further Reading" that might be interesting and helpful in this context.
I'm afraid, that's all I can say, given your brief description.