Repository: microsoft/terminal
File: src/renderer/atlas/AtlasEngine.api.cpp (C++)

Code before:
    if (_api.s->target->useSoftwareRendering != enable)
    {
        _api.s.write()->target.write()->useSoftwareRendering = enable;
    }
}

void AtlasEngine::SetWarningCallback(std::function<void(HRESULT)> pfn) noexcept
{
    _p.warningCallback = std::move(pfn);
}

[[nodiscard]] HRESULT AtlasEngine::SetWindowSize(const til::size pixels) noexcept
{
    u16x2 newSize;
    RETURN_IF_FAILED(vec2_narrow(pixels.width, pixels.height, newSize));

    // At the time of writing:
    // When Win+D is pressed, `TriggerRedrawCursor` is called and a render pass is initiated.
    // As conhost is in the background, GetClientRect will return {0,0} and we'll get called with {0,0}.
    // This isn't a valid value for _api.sizeInPixel and would crash _recreateSizeDependentResources().
    if (_api.s->targetSize != newSize && newSize != u16x2{})
    {
        _api.s.write()->targetSize = newSize;
    }

    return S_OK;
}

[[nodiscard]] HRESULT AtlasEngine::UpdateFont(const FontInfoDesired& fontInfoDesired, FontInfo& fontInfo, const std::unordered_map<std::wstring_view, uint32_t>& features, const std::unordered_map<std::wstring_view, float>& axes) noexcept
{
    static constexpr std::array fallbackFaceNames{ static_cast<const wchar_t*>(nullptr), L"Consolas", L"Lucida Console", L"Courier New" };
    auto it = fallbackFaceNames.begin();
    const auto end = fallbackFaceNames.end();

    for (;;)
    {
        try
        {
            _updateFont(*it, fontInfoDesired, fontInfo, features, axes);
            return S_OK;
        }
        catch (...)
        {
            ++it;
            if (it == end)
            {
                RETURN_CAUGHT_EXCEPTION();
            }
            else
            {
                LOG_CAUGHT_EXCEPTION();

Review comment (suggestion):
This PR now fixes the issue from two directions:
* Avoid ever setting `targetSize` to anything that has a 0 on either width or height

Code after:
    if (_api.s->target->useSoftwareRendering != enable)
    {
        _api.s.write()->target.write()->useSoftwareRendering = enable;
    }
}

void AtlasEngine::SetWarningCallback(std::function<void(HRESULT)> pfn) noexcept
{
    _p.warningCallback = std::move(pfn);
}

[[nodiscard]] HRESULT AtlasEngine::SetWindowSize(const til::size pixels) noexcept
{
    // When Win+D is pressed, `GetClientRect` returns {0,0}.
    // There's probably more situations in which our callers may pass us invalid data.
    if (!pixels)
    {
        return S_OK;
    }

    const u16x2 newSize{
        gsl::narrow_cast<u16>(clamp<til::CoordType>(pixels.width, 1, u16max)),
        gsl::narrow_cast<u16>(clamp<til::CoordType>(pixels.height, 1, u16max)),
    };

    if (_api.s->targetSize != newSize)
    {
        _api.s.write()->targetSize = newSize;
    }

    return S_OK;
}

[[nodiscard]] HRESULT AtlasEngine::UpdateFont(const FontInfoDesired& fontInfoDesired, FontInfo& fontInfo, const std::unordered_map<std::wstring_view, uint32_t>& features, const std::unordered_map<std::wstring_view, float>& axes) noexcept
{
    static constexpr std::array fallbackFaceNames{ static_cast<const wchar_t*>(nullptr), L"Consolas", L"Lucida Console", L"Courier New" };
    auto it = fallbackFaceNames.begin();
    const auto end = fallbackFaceNames.end();

    for (;;)
    {
        try
        {
            _updateFont(*it, fontInfoDesired, fontInfo, features, axes);
            return S_OK;
        }
        catch (...)
        {
            ++it;
            if (it == end)
            {