-
Fix reporting VK_ERROR_OUT_OF_HOST_MEMORY · 4cd9767eNicolas Capens authored
The regular C++ operator new calls the installed new-handler on out-of-memory, which by default throws std::bad_alloc when exception handling is enabled, or aborts when not. Under no circumstance is null returned. Furthermore, LLVM installs a new-handler itself, which also ends up aborting the program. Using the std::nothrow version of new does not work because it still calls the new-handler. Installing our own non-fatal new-handler is also futile because the new operator will re-attempt allocation. Setting the new-handler to nullptr will cause the nothrow version of new to return null on out-of-memory. However, this still overrides any new handler which the application may have installed, or, can be overridden by the application again at any point. Instead just use legacy malloc(), which is guaranteed to never throw and returns null on failure. This is already checked for by vk::Create() and it reports VK_ERROR_OUT_OF_HOST_MEMORY. Bug: b/137093675 Change-Id: I6c9ccf738cfd21af9e52382d6e7755071d613d39 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34028 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by:
Ben Clayton <bclayton@google.com> Reviewed-by:
Chris Forbes <chrisforbes@google.com> Tested-by:
Nicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
4cd9767e
×