Repository: microsoft/terminal
File: src/renderer/base/renderer.cpp (C++)

Code before:
            // isn't near as bad as the entire application aborting. We're a component. We shouldn't
            // abort applications that host us.
            return S_FALSE;
        }

        // Add a bit of backoff.
        // Sleep 150ms, 300ms, 450ms before failing out and disabling the renderer.
        Sleep(renderBackoffBaseTimeMilliseconds * (maxRetriesForRenderEngine - tries));
    }

    return S_OK;
}

[[nodiscard]] HRESULT Renderer::_PaintFrame() noexcept
{
    {
        _pData->LockConsole();
        auto unlock = wil::scope_exit([&]() {
            _pData->UnlockConsole();
        });

        // Last chance check if anything scrolled without an explicit invalidate notification since the last frame.
        _CheckViewportAndScroll();

        _invalidateCurrentCursor(); // Invalidate the previous cursor position.
        _updateCursorInfo();
        _invalidateCurrentCursor(); // Invalidate the new cursor position.

        _invalidateOldComposition();
        _compositionCache.reset();
        _prepareNewComposition();

        FOREACH_ENGINE(pEngine)
        {
            RETURN_IF_FAILED(_PaintFrameForEngine(pEngine));
        }
    }

    FOREACH_ENGINE(pEngine)
    {
        RETURN_IF_FAILED(pEngine->Present());
    }

    return S_OK;
}

[[nodiscard]] HRESULT Renderer::_PaintFrameForEngine(_In_ IRenderEngine* const pEngine) noexcept
try
{
    FAIL_FAST_IF_NULL(pEngine); // This is a programming error. Fail fast.


Review comment (suggestion):
shouldn't this come before `_updateCursorInfo`? Since `_updateCursorInfo` can change `_currentCursorOptions.inViewport`

Code after:
            // isn't near as bad as the entire application aborting. We're a component. We shouldn't
            // abort applications that host us.
            return S_FALSE;
        }

        // Add a bit of backoff.
        // Sleep 150ms, 300ms, 450ms before failing out and disabling the renderer.
        Sleep(renderBackoffBaseTimeMilliseconds * (maxRetriesForRenderEngine - tries));
    }

    return S_OK;
}

[[nodiscard]] HRESULT Renderer::_PaintFrame() noexcept
{
    {
        _pData->LockConsole();
        auto unlock = wil::scope_exit([&]() {
            _pData->UnlockConsole();
        });

        // Last chance check if anything scrolled without an explicit invalidate notification since the last frame.
        _CheckViewportAndScroll();

        _invalidateCurrentCursor(); // Invalidate the previous cursor position.
        _invalidateOldComposition();

        _updateCursorInfo();
        _compositionCache.reset();

        _invalidateCurrentCursor(); // Invalidate the new cursor position.
        _prepareNewComposition();

        FOREACH_ENGINE(pEngine)
        {
            RETURN_IF_FAILED(_PaintFrameForEngine(pEngine));
        }
    }

    FOREACH_ENGINE(pEngine)
    {
        RETURN_IF_FAILED(pEngine->Present());
    }

    return S_OK;
}

[[nodiscard]] HRESULT Renderer::_PaintFrameForEngine(_In_ IRenderEngine* const pEngine) noexcept
try
{
    FAIL_FAST_IF_NULL(pEngine); // This is a programming error. Fail fast.