Yesterday I was working away on an application for a client, moving their (custom) menu code to use wxWindows. This application has different modes (empty, design, and run) where the menu bar is completely different.
Ok, that’s no problem, we just reset the menu bar and populate it with the new menus.
It turned out to not be that simple… I had code something like this:
for (int i=0; i Remove(i)); }
(when you remove a menu in wxWindows you are responsible for deleting it. Fair’s Fair.)
I was getting a crash - ‘attempting to remove an already detached menu’. I gave this a minute of puzzling, and sent an email to the wxWindows Users mailing list. Plus a patch they could apply to a sample app, to reproduce with.
I hadn’t heard anything back from the list, so I decided to pursue it myself. Rebuild my wxWindows library (needed to do this for some reason), got my breakpoints all set, and did some tracing.
It turns out that there was one method, Detach() that was being called twice. One time at the base level, and one time at the Mac Specific level. Removed the Mac Specific call and all was fine.
Did a diff on the file, and submitted the patch to the wxWindows Project Page on SF.
Open Source is massively cool because I can do that. If there’s a problem with the library, I can go and try to find the solution. If there’s a problem in a closed source library (for example: Apple’s Databrowser control) I have to wait for Apple to read my bug report, reproduce it, and maybe maybe fix it in a future update.
With Open Source, the fix is in my source tree now. I don’t have to work around the issue, because right now, for me, there is no issue.
It took me a hour and 45 minutes to track down the bug. A good 30 of those minutes were spent waiting for wxWindows to compile completely. To work around the bug? At least 3 (You can only call the SetMenuBar() function once per window, so just creating and resetting the menu bar wouldn’t have worked - I would have had to delete and recreate the entire controlling window for that menu).
For those of you who are puzzled at the above windows-controlling-menus statement, wxWindows is a cross-platform app, and that means it uses the Windows/Linux paradigm of one menubar per window, not the Mac one menubar per application rule.
That’s what my code looks like - I have one window controlling the application’s menus. Since I’m on the Mac, and none of my other windows have menu bars, my one window controls the global menu bar, and nobody is the wiser.
Open Source might not be the end all, be all of software, but it sure is useful sometimes.