Side Quest - Beware of side effects!
This is the first in a series of mini programming blog posts I’ve titled ‘Side Quest’. I plan to make more of these in the future too!
I have recently been working on a new GUI for the Xenia Emulator. Yesterday I encountered a strange issue with the code for the Combobox widget… In “Debug” builds everything worked fine. But in “Release” builds, the combobox was empty! The bulk of the code is shown below, see if you can spot the issue.
|
|
If you spotted the mistake quickly, it is very likely you have encountered this problem previously, as it’s one they don’t teach you in programming school.
The problem was that in “Release” mode, the assert_true()
macro is compiled out so Initialize()
is never called!
This bug took me way too long to spot, made harder by the lack of errors.
The lesson here is of course: don’t execute code with side-effects in an assert
block