Some of the primitive nodes can return null in an error condition.
I think this is reasonable behavior, but it's confusing mixed with
adding a maderial slot in calling functions. This is the second crash
caused by that confusion. I think it's simpler to add the slot right when
allocating the mesh, and it will lend itself better to copy & paste coding
in the future.
Another method would be returning an empty mesh rather than null
in these cases, I don't really think that's better though.