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 <noreply@anthropic.com>
This commit is contained in:
@@ -182,6 +182,11 @@ fn set_badge_count(count: u32, window: tauri::Window) -> Result<(), String> {
|
|||||||
let hbm_color =
|
let hbm_color =
|
||||||
CreateDIBSection(Some(hdc), &bmi, DIB_RGB_COLORS, &mut bits, None, 0)
|
CreateDIBSection(Some(hdc), &bmi, DIB_RGB_COLORS, &mut bits, None, 0)
|
||||||
.map_err(|e| e.to_string())?;
|
.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 old_bm = SelectObject(hdc, hbm_color.into());
|
||||||
|
|
||||||
let hbrush = CreateSolidBrush(COLORREF(0x003030DD));
|
let hbrush = CreateSolidBrush(COLORREF(0x003030DD));
|
||||||
|
|||||||
Reference in New Issue
Block a user