It's been an interesting 24 hours.
Last night, I dove back into my broken high-resolution patchset for libfreenect, the open-source Kinect drivers. This debugging trip took me through compiling libusb from source to enable debug messages, finding that libusb was getting a status code of -2, searching through the Linux kernel for the matching ioctl(), and eventually finding that the command in question was returning -ENOENT, which means that the device completely disappeared. As a result, subsequent libusb calls to the same open device handle would cause libusb to crash. Ordinarily, you'd stop sending commands to the device as soon as it disappears, but the cleanup code in our demo wanted to shut the device down cleanly.
It took a while for me to realize what this meant - through a particular series of control commands to the Kinect, I was CRASHING THE KINECT, and it stopped responding to further communications. After a couple of random tests, I hit on the solution: don't send the "stop the video" command more times than you send the "start the video" command.
Then there was another bug in my own code that had evaded me for two months where, when starting a video stream, I'd queue up 16 isochronous transfers before aborting because the pixelformat/resolution combination was invalid. Obviously, I should have done the check up front and failed early, before calling any functions with side-effects. If I'd followed marcan's software development advice, I would have figured this out a long time ago. He writes:
"One great technique to use is to do as much as possible in advance. Gather all required information about the system, read any required data files, prepare any modifications, and only at the very end actually commit the changes to the device. If anything goes wrong during the preparations, you can just abort the entire operation and be certain that the device is still safe."
Bingo. And as soon as I did that to my code, everything started working consistently. Thus, I'm now in cleanup mode for this patchset, which I hope to submit upstream some time in the next couple days. Many thanks to Antonio Ospite for testing and reviewing my patches.
So, all that was last night. As for today: the noteworthy event was the miracle berry social hour.
The CS department regularly hosts social hours, which usually consist of a person or two getting a bunch of somewhat-themed foods and beverages, and then bunches of people would gather and chat for a good while. This week, Justin (who is one of my teammates for my security project) organized a social hour themed around the miracle berry. The interesting thing about this particular berry is that it contains miraculin, a glycoprotein that fools your taste buds into thinking sour things taste sweet. It's pretty crazy.
So, Justin had procured $60 worth of miraculin tablets and $40 worth of other foods, like lemons, limes, oranges, tomatos, pickles, radishes, and so forth, and they were all sitting neatly arranged on a table outside Wozniak lounge. I let half a tab of the miraculin-cornstarch mix dissolve on my tongue, and then ate about a third of an orange slice and nibbled on a lemon wedge. It was pretty weird, having the lemon taste so sweet.
Then I started getting a headache, so I went inside the Woz to sit down. Shortly thereafter, I realized this was no normal headache, but rather a low-blood-pressure headache. I took off my backpack and put my head between my legs, in an attempt to stay conscious.
Then the nausea hit. I hastily moved to a chair next to the giant trash cans. Justin watched over me as I described as best I could that I was suddently unwell, my blood pressure was dropping, I might pass out, no, I'm not diabetic, no, I don't have any known food allergies, and no, I don't need an ambulance quite yet, but if I do pass out, that might be a good next step. Then I puked what little I had eaten up, which was a most unusual experience. Thanks to the miraculin, the bile didn't really taste bad at all - it was mostly sweet, with a very small hint of puke flavor.
By this time, I'd attracted a small crowd of folk who watched over me as the color slowly returned to my sickly-white face. Justin brought me my backpack and my "Powered by Open Source" hoodie which lay across the room. Another guy brought me a cup of lukewarm water. I shivered in shock for a bit, but remained conscious, and after a while, my fingernails turned from blue back to their normal pink, and I was able to stand up and walk around again, after which I went home and took a nap.
Other thoughts: I've had this particular response to stimuli three times in the past six years or so. All three were after receiving flu shots, so I've come to associate the headache, optional passing out, and optional nausea with that particular immunization (although really, it's just vasovagal response). As for what happened today: I'm unsure, but if I had to guess, I'd say maybe I'm one of the rare people with a miracle berry allergy - the internet seems to suggest that in rare cases, people get nausea and cold sweats after consuming miraculin. I was quite proud that I did not pass out this time, and in retrospect, this was perhaps one of the best circumstances I could have had such a reaction in. After all, I was surrounded by intelligent friends who looked out for me and entertained me while I recovered.
Clearly, I'll have to test this out again under controlled conditions.