Mesh.CreateFromBox returns null - Circumstances?

Can anyone explain what circumstances cause null on return from Mesh.CreateFromBox?

The case is dead simple:

Putting it in do{}while(_boxMesh == null) causes an endless loop. This is the first time I’ve seen null returned from this method, and I’d like to know where it can fail and why. I mean, what’s the reason that the internal method returns IntPtr.Zero obviously.

Ahh … maxCorner typo - y is still minus, so box is flat. Though it still should return mesh (?) flat or just Mesh with one face (?). Although it would still be nice to know what edge cases are discarded and when null is expected.

A quick ride through the source code tells me these conditions that would definitely return null.

  1. If corners is null
  2. If corners has less than 8 points in it
  3. If the number of sides of this box does not equal 6
  4. If any of the sides of the box are invalid

@CallumSykes Thanks a lot for your input. Good to know that if something may bring flat boxes, some fallback is a must here :+1:

I think most if not all C# APIs in Rhino will return null on an error, and when it comes to geometry there are many possible errors. I’d recommend always checking any method that outputs a class for null.