vulkan-renderer icon indicating copy to clipboard operation
vulkan-renderer copied to clipboard

Throw an exception if somebody tries to access childs() on a cube which has no childs

Open IAmNotHanni opened this issue 4 years ago • 3 comments

const auto world = std::make_shared<world::Cube>(world::Cube::Type::EMPTY, 1.0f, glm::vec3{0, 0, 0});

// uh oh
world->childs()[3]->set_type(world::Cube::Type::EMPTY);

IAmNotHanni avatar Apr 17 '21 23:04 IAmNotHanni

Not sure if we really require an exception here. Also you can use at https://en.cppreference.com/w/cpp/container/array/at. I would consider this as an intended behaviour.

IceflowRE avatar Apr 19 '21 11:04 IceflowRE

One the one hand you are right, since those methods actually belong to performance critical code. On the other hand .at would not prevent us from sccessing the methods of instances which do not exist, which would throw an exception anyways.

IAmNotHanni avatar Apr 19 '21 11:04 IAmNotHanni

On the other hand .at would not prevent us from sccessing the methods of instances which do not exist, which would throw an exception anyways.

childs() is noexcept actually, it is just a getter.

On the other hand .at would not prevent us from sccessing the methods of instances which do not exist

It will as it will throw an Out of Bounds Exception. The given child array is empty.

IceflowRE avatar Apr 19 '21 12:04 IceflowRE