Null pointer exception protection against invalid material IDs