Move cegui dynamic casts to fix a shutdown crash