https://git.reactos.org/?p=reactos.git;a=commitdiff;h=13b34253694811739064de9efa6be2881b138c19

commit 13b34253694811739064de9efa6be2881b138c19
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sat Jan 29 02:20:26 2022 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sun Jan 30 01:02:07 2022 +0100

    [CONSOLE.CPL] Use fallback brushes for text preview in case 
CreateSolidBrush() fails (e.g. low memory scenario).
---
 dll/cpl/console/colors.c |  6 ++----
 dll/cpl/console/layout.c | 19 ++++++++-----------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/dll/cpl/console/colors.c b/dll/cpl/console/colors.c
index b4d1c337e01..f6a8c40e947 100644
--- a/dll/cpl/console/colors.c
+++ b/dll/cpl/console/colors.c
@@ -26,10 +26,8 @@ PaintStaticControls(
                 ARRAYSIZE(pConInfo->ColorTable) - 1);
 
     hBrush = CreateSolidBrush(pConInfo->ColorTable[index]);
-    if (!hBrush) return;
-
-    FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
-    DeleteObject(hBrush);
+    FillRect(drawItem->hDC, &drawItem->rcItem, hBrush ? hBrush : 
GetStockObject(BLACK_BRUSH));
+    if (hBrush) DeleteObject(hBrush);
 
     if (ActiveStaticControl == index)
         DrawFocusRect(drawItem->hDC, &drawItem->rcItem);
diff --git a/dll/cpl/console/layout.c b/dll/cpl/console/layout.c
index a94bcb53241..8430b3de218 100644
--- a/dll/cpl/console/layout.c
+++ b/dll/cpl/console/layout.c
@@ -390,8 +390,8 @@ WinPrev_OnDraw(
 
     /* Draw the console background */
     hBrush = 
CreateSolidBrush(pConInfo->ColorTable[BkgdAttribFromAttrib(pConInfo->ScreenAttributes)]);
-    FillRect(hDC, &rcWin, hBrush);
-    DeleteObject(hBrush);
+    FillRect(hDC, &rcWin, hBrush ? hBrush : GetStockObject(BLACK_BRUSH));
+    if (hBrush) DeleteObject(hBrush);
 }
 
 static LRESULT CALLBACK
@@ -489,20 +489,18 @@ PaintText(
     nbkColor = pConInfo->ColorTable[BkgdAttribFromAttrib(CurrentAttrib)];
     ntColor  = pConInfo->ColorTable[TextAttribFromAttrib(CurrentAttrib)];
 
+    /* Draw the console background */
     hBrush = CreateSolidBrush(nbkColor);
-    if (!hBrush) return;
+    FillRect(drawItem->hDC, &drawItem->rcItem, hBrush ? hBrush : 
GetStockObject(BLACK_BRUSH));
+    if (hBrush) DeleteObject(hBrush);
 
+    /* Refresh the font preview, getting a new font if necessary */
     if (FontPreview.hFont == NULL)
         RefreshFontPreview(&FontPreview, pConInfo);
 
+    /* Draw the preview text using the current font */
     hOldFont = SelectObject(drawItem->hDC, FontPreview.hFont);
-    //if (hOldFont == NULL)
-    //{
-    //    DeleteObject(hBrush);
-    //    return;
-    //}
-
-    FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
+    // if (!hOldFont) return;
 
     /* Add a few space between the preview window border and the text sample */
     InflateRect(&drawItem->rcItem, -2, -2);
@@ -514,7 +512,6 @@ PaintText(
     SetBkColor(drawItem->hDC, pbkColor);
 
     SelectObject(drawItem->hDC, hOldFont);
-    DeleteObject(hBrush);
 }
 
 

Reply via email to