From 5cc84991f2712ecbaceebbe604d367c701f43831 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 15 Jun 2026 00:10:01 -0400 Subject: [PATCH] fix(badge): zero-init DIB bits buffer to eliminate black square CreateDIBSection does not guarantee zeroed memory. Uninitialized bytes with non-zero RGB but zero alpha were getting alpha=255 set by the existing pixel loop, causing a black square around the badge circle. Zeroing with write_bytes before GDI drawing ensures only explicitly painted pixels are opaque. Co-Authored-By: Claude Sonnet 4.6 --- src-tauri/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 38c35f6..8501fdf 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -182,6 +182,11 @@ fn set_badge_count(count: u32, window: tauri::Window) -> Result<(), String> { let hbm_color = CreateDIBSection(Some(hdc), &bmi, DIB_RGB_COLORS, &mut bits, None, 0) .map_err(|e| e.to_string())?; + // Zero-init so undrawn pixels are fully transparent (CreateDIBSection + // does not guarantee zeroed memory; garbage bytes cause a black square). + if !bits.is_null() { + std::ptr::write_bytes(bits as *mut u8, 0, (size * size * 4) as usize); + } let old_bm = SelectObject(hdc, hbm_color.into()); let hbrush = CreateSolidBrush(COLORREF(0x003030DD));