fix(badge): zero-init DIB bits buffer to eliminate black square
Build Lotus Chat Desktop / prepare (push) Successful in 3s
Build Lotus Chat Desktop / update-manifest (push) Has been cancelled
Build Lotus Chat Desktop / build-windows (push) Has been cancelled
Build Lotus Chat Desktop / build-linux (push) Has been cancelled

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 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 00:10:01 -04:00
parent 150a1921f9
commit 5cc84991f2
+5
View File
@@ -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));