Obviously, once you have identified the differences between a working and a non working case this difference is a prime candidate for the problem.
You need to read and understand the cuboid geometry setup as well as the prepareGeometry function in order to identify what you need to adapt for your case.
I also, again, recommend a thorough read of the user guide lessons.