ash icon indicating copy to clipboard operation
ash copied to clipboard

Make bindings resilient to OOM errors

Open tomaka opened this issue 1 year ago • 1 comments

This PR proposes a relatively simple but maybe controversial change.

In the functions that return a Vec, instead of using Vec::with_capacity and similar, we use Vec::new() followed with Vec::try_reserve. If try_reserve fails, we return VK_ERROR_OUT_OF_HOST_MEMORY.

Note that there's no shorter way on stable Rust to do this. Notably, try_with_capacity is unstable.

If I'm not mistaken, the bindings now never panic in case of OOM.

I personally don't have a need for this change, but I thought that this was a neat thing to add.

tomaka avatar Jun 08 '24 15:06 tomaka

If we end up doing this, is there a lint that enables us to catch accidental/new remaining calls to Vec::with_capacity() and friends, that may result in panicking allocations?

Alternatively we could list such functions in disallowed-methods in clippy.toml via clippy::disallowed_methods.

I personally don't have a need for this change, but I thought that this was a neat thing to add.

Might be neat, but if we do this we're better complete about it :)

MarijnS95 avatar Dec 03 '24 14:12 MarijnS95