Not all possible depths are available in all servers. Run xdpyinfo | grep depths
to see what yours support, or call XListDepths
from your application.
For example, on my home computer the X server supports depth of 16, but on my work computer it doesn't.
EDIT Window depth must exactly match visual depth, or BadMatch error occurs.
XListDepths
may be used to query which visuals support given depth. If all visuals have depth of 24, then every window must have depth of 24. Not all listed depths may be realised as visuals on a given server.