Ok,

if my code exits this means that either the number of returned devices is 0, or one of the handles is NULL. Can you do a printf on these variables to find out?
Also it is necesary for this sample code that two Wiimotes are connected all the time as I check both handles for validity.

Maybe your driver for some reason leaves a gap in the enumeration and thus one of the handles is NULL.

----------------------------

Only thing I see in your code without testing is that you are calling wiimote_getdevices() in a while loop. This is not a good idea as this function is slo, and I think I'm also disconnecting and reconencting all Wiimotes in order to find out the number of Wiimotes.
Call it once before the while loop.