Wednesday, September 26, 2012

Release != Debug: strange C++ problem

I've been working on the new Managed Switch Port Mapping Tool v2 quite a bit lately and ran into a strange problem: one function in the program (saving to an XML file) was causing it to hang up in Release mode, but never in Debug mode. The program imported three static libraries, one is the BCGSoft 18 library (cool stuff), another is the CodeProject Ultimate Grid (I'm the KVT in the source code notes) and the last is the CodeProject Ultimate Toolbox. Of the three, the BCGSoft libary is the most recent addition. This problem never happened in and it doesn't use the BCGSoft library.

The first thing I did was convert the Release version code for all of them so that it included Debug info. That was a bit tedious, but went OK. Then I was able to press the Save button and step through to see where it was hanging up. That didn't go so well. It would hang up in different places. It seemed to be a stack or memory issue. I tried increasing stack and heap in the main executable, but it didn't help.

Finally after 5 hours, I decided to look and see just how much of the Ultimate Toolbox library I was actually using. It turns out I was only using the OXParser and OXRegistryItem. By moving them and their supporting files (roughly 6 other cpp and h) into the main executable, I was able to remove the linkage to the UTlibStaticR. I suspect that the BCGSoft library has some functions with the same name as Ultimate Toolbox, but I wasn't going to look through pages and pages of import listings to see wheich ones. Eliminating the library was simpler. And, yes, I put back the normal release settings to remove debugging from the release version and it works fine now.

No comments: