Skip to content

Commit df03631

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

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ 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 = mem::zeroed::<WindowsAndMessaging::WNDCLASSEXA>();
288+
WindowsAndMessaging::GetClassInfoExA(
289+
Some(instance.into()),
290+
PCSTR(name.as_ptr().cast()),
291+
&mut wc,
292+
)
293+
.is_ok()
294+
};
295+
if already_exists {
296+
return Ok(name);
297+
}
298+
284299
// Use a wrapper function for compatibility with `windows-rs`.
285300
unsafe extern "system" fn wnd_proc(
286301
window: Foundation::HWND,

0 commit comments

Comments
 (0)