diff --git a/src/renderer/atlas/AtlasEngine.api.cpp b/src/renderer/atlas/AtlasEngine.api.cpp index 0e2f7941688..2f15b911184 100644 --- a/src/renderer/atlas/AtlasEngine.api.cpp +++ b/src/renderer/atlas/AtlasEngine.api.cpp @@ -597,7 +597,7 @@ void AtlasEngine::_resolveFontMetrics(const wchar_t* requestedFaceName, const Fo { const auto requestedFamily = fontInfoDesired.GetFamily(); auto requestedWeight = fontInfoDesired.GetWeight(); - auto fontSize = fontInfoDesired.GetFontSize(); + auto fontSize = std::clamp(fontInfoDesired.GetFontSize(), 1.0f, 100.0f); auto requestedSize = fontInfoDesired.GetEngineSize(); if (!requestedFaceName) diff --git a/src/renderer/atlas/BackendD2D.cpp b/src/renderer/atlas/BackendD2D.cpp index f2f2e67fa18..347311f166b 100644 --- a/src/renderer/atlas/BackendD2D.cpp +++ b/src/renderer/atlas/BackendD2D.cpp @@ -39,18 +39,28 @@ void BackendD2D::Render(RenderingPayload& p) } _renderTarget->BeginDraw(); + try + { #if ATLAS_DEBUG_SHOW_DIRTY || ATLAS_DEBUG_DUMP_RENDER_TARGET - // Invalidating the render target helps with spotting Present1() bugs. - _renderTarget->Clear(); + // Invalidating the render target helps with spotting Present1() bugs. + _renderTarget->Clear(); #endif - _drawBackground(p); - _drawCursorPart1(p); - _drawText(p); - _drawCursorPart2(p); - _drawSelection(p); + _drawBackground(p); + _drawCursorPart1(p); + _drawText(p); + _drawCursorPart2(p); + _drawSelection(p); #if ATLAS_DEBUG_SHOW_DIRTY - _debugShowDirty(p); + _debugShowDirty(p); #endif + } + catch (...) + { + // In case an exception is thrown for some reason between BeginDraw() and EndDraw() + // we still technically need to call EndDraw() before releasing any resources. + LOG_IF_FAILED(_renderTarget->EndDraw()); + throw; + } THROW_IF_FAILED(_renderTarget->EndDraw()); #if ATLAS_DEBUG_DUMP_RENDER_TARGET diff --git a/src/renderer/atlas/BackendD3D.cpp b/src/renderer/atlas/BackendD3D.cpp index 836fd57fe36..54de45584ee 100644 --- a/src/renderer/atlas/BackendD3D.cpp +++ b/src/renderer/atlas/BackendD3D.cpp @@ -219,6 +219,18 @@ BackendD3D::BackendD3D(const RenderingPayload& p) #endif } +#pragma warning(suppress : 26432) // If you define or delete any default operation in the type '...', define or delete them all (c.21). +BackendD3D::~BackendD3D() +{ + // In case an exception is thrown for some reason between BeginDraw() and EndDraw() + // we still technically need to call EndDraw() before releasing any resources. + if (_d2dBeganDrawing) + { +#pragma warning(suppress : 26447) // The function is declared 'noexcept' but calls function '...' which may throw exceptions (f.6). + LOG_IF_FAILED(_d2dRenderTarget->EndDraw()); + } +} + void BackendD3D::ReleaseResources() noexcept { _renderTargetView.reset(); diff --git a/src/renderer/atlas/BackendD3D.h b/src/renderer/atlas/BackendD3D.h index 9442817decc..90404271d2d 100644 --- a/src/renderer/atlas/BackendD3D.h +++ b/src/renderer/atlas/BackendD3D.h @@ -14,6 +14,7 @@ namespace Microsoft::Console::Render::Atlas struct BackendD3D : IBackend { BackendD3D(const RenderingPayload& p); + ~BackendD3D() override; void ReleaseResources() noexcept override; void Render(RenderingPayload& payload) override; diff --git a/src/renderer/atlas/common.h b/src/renderer/atlas/common.h index 04e6e15350f..2649113408c 100644 --- a/src/renderer/atlas/common.h +++ b/src/renderer/atlas/common.h @@ -391,9 +391,9 @@ namespace Microsoft::Console::Render::Atlas til::generational cursor; til::generational misc; // Size of the viewport / swap chain in pixel. - u16x2 targetSize{ 1, 1 }; + u16x2 targetSize{ 0, 0 }; // Size of the portion of the text buffer that we're drawing on the screen. - u16x2 viewportCellCount{ 1, 1 }; + u16x2 viewportCellCount{ 0, 0 }; // The position of the viewport inside the text buffer (in cells). u16x2 viewportOffset{ 0, 0 }; };