Worst & Best ever

I am in the middle of trying to fix one of my worst and best bugs ever. I am still getting a random crash at startup probably 5% of the time. I have narrowed it down to a total race condition somewhere. I believe it's in my messaging system somewhere. I'm also pretty sure it's due to my MIS-use of STL containers which are not thread safe. I am in the process of attempting to control access to my messaging system through mutexes which is going suprisingly well considering how scary it sounds.

So in amongst all this pain is some good. In my hair pulling episodes of trying to track this problem down I've investigated every possibility imaginable and have fixed a tonne of other bugs in the process!

First I thought that it might be a COM issue around DirectSound. I am not a COM wizard but I've had some problems in the past using single threaded apartments and objects getting locked or lost. So I switch to a MTA and in the process found that I had some stray calls to CoInitialize() lying around from a previous refactoring of my resource manager. A couple lines cut out and I magically get a 50% improvement in frame rate!! I still don't understand it. The only thing I can guess is that I had some extra marshalling going on with my textures which meant a lot of extra overhead. Either way 50% is huge! I may now run on lower end machines in a window.

After the COM didn't fix my main problem I went looking for memory leaks/overwrites. This helped me find a few leaks that I didn't know about which is a plus. But more importantly while running using MMGR from Fluid I found some other weird race conditions in my shut down process that got exposed thanks to the mem manager slowing things down differently. This lead me to making my thread shut down more robust.

All in all my engine is now faster, tighter and more robust. If I can only find this random crash I'll be sitting sweet. Here's hoping my mutexes do the trick.