Skip to content

Commit 1f2f3cc

Browse files
committed
fix double window class registration
1 parent b599252 commit 1f2f3cc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ By @SupaMaggie70Incorporated in [#8206](https://github.com/gfx-rs/wgpu/pull/8206
167167
#### GLES
168168

169169
- Fix race when downloading texture from compute shader pass. By @SpeedCrash100 in [#8527](https://github.com/gfx-rs/wgpu/pull/8527)
170+
- Fix double window class registration when dynamic libraries are used. By @Azorlogh in [#8548](https://github.com/gfx-rs/wgpu/pull/8548)
170171

171172
#### hal
172173

wgpu-hal/src/gles/wgl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ fn create_global_window_class() -> Result<CString, crate::InstanceError> {
281281
let name = format!("wgpu Device Class {:x}\0", class_addr as usize);
282282
let name = CString::from_vec_with_nul(name.into_bytes()).unwrap();
283283

284+
// The window class may already be registered if we are a dynamic library that got
285+
// unloaded & loaded back into the same process. If so, just skip creation.
286+
let already_exists = unsafe {
287+
let mut wc = std::mem::zeroed::<WindowsAndMessaging::WNDCLASSEXA>();
288+
WindowsAndMessaging::GetClassInfoExA(instance, PCSTR(name.as_ptr().cast()), &mut wc).is_ok()
289+
};
290+
if already_exists {
291+
return Ok(name);
292+
}
293+
284294
// Use a wrapper function for compatibility with `windows-rs`.
285295
unsafe extern "system" fn wnd_proc(
286296
window: Foundation::HWND,

0 commit comments

Comments
 (0)