Fixed bug where countMenuChildren returned zero

Fixes this error in the 2.5.x branch as well.

(And this time I mean it.)