microsoft / cppwinrt

C++/WinRT
MIT License
1.61k stars 232 forks source link

Bug: throw_hresult should treat ERROR_COMMITMENT_LIMIT as OOM #1399

Closed DanielJump closed 3 months ago

DanielJump commented 3 months ago

Version

No response

Summary

We are seeing this HRESULT get thrown sometimes and think it should be mapped to std::bad_alloc by throw_hresult.

Reproducible example

No response

Expected behavior

No response

Actual behavior

No response

Additional comments

No response

DanielJump commented 3 months ago

Suggested fix:

    if (result.code() == -2147023441 /*HRESULT_FROM_WIN32(ERROR_COMMITMENT_LIMIT)*/)
    {
        throw std::bad_alloc();
    }

Stack overflow discussion about this issue. https://stackoverflow.com/questions/5419524/outofmemoryexception-error-commitment-limit-with-a-lot-of-free-memory-in-the-s

kennykerr commented 3 months ago

There are various error codes that can be used to indicate some kind of resource exhaustion and the error mapping in C++/WinRT is not extensible. In hindsight we should simply have had a single hresult_error type that encompassed all HRESULT values and avoided any transformation.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 10 days with no activity. Remove stale label or comment or this will be closed in 5 days.