fix double window class registration (#8548)

This commit is contained in:
Alix Bott 2025-11-26 22:51:41 +00:00 committed by GitHub
parent ee08b916e5
commit 43c5d27219
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -171,6 +171,7 @@ By @SupaMaggie70Incorporated in [#8206](https://github.com/gfx-rs/wgpu/pull/8206
#### GLES
- Fix race when downloading texture from compute shader pass. By @SpeedCrash100 in [#8527](https://github.com/gfx-rs/wgpu/pull/8527)
- Fix double window class registration when dynamic libraries are used. By @Azorlogh in [#8548](https://github.com/gfx-rs/wgpu/pull/8548)
#### hal

View File

@ -281,6 +281,21 @@ fn create_global_window_class() -> Result<CString, crate::InstanceError> {
let name = format!("wgpu Device Class {:x}\0", class_addr as usize);
let name = CString::from_vec_with_nul(name.into_bytes()).unwrap();
// The window class may already be registered if we are a dynamic library that got
// unloaded & loaded back into the same process. If so, just skip creation.
let already_exists = unsafe {
let mut wc = mem::zeroed::<WindowsAndMessaging::WNDCLASSEXA>();
WindowsAndMessaging::GetClassInfoExA(
Some(instance.into()),
PCSTR(name.as_ptr().cast()),
&mut wc,
)
.is_ok()
};
if already_exists {
return Ok(name);
}
// Use a wrapper function for compatibility with `windows-rs`.
unsafe extern "system" fn wnd_proc(
window: Foundation::HWND,