[3d] simplify some code by moving error check